You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
951 B

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
@interface Functions : NSObject
@property(strong) void (^block)(void);
@end
@implementation Functions
+ (instancetype)autoUpdating {
static Functions* a;
dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
a = [self alloc];
a.block = ^{
};
});
return a;
}
static void dispatch_once2(dispatch_once_t* predicate, dispatch_block_t block);
+ (instancetype)autoUpdating2 {
static Functions* a;
dispatch_once_t onceToken;
dispatch_once2(&onceToken, ^{
a = [self alloc];
a.block = ^{
};
});
return a;
}
@end
int main() {
Functions* a = [Functions autoUpdating];
Functions* a2 = [Functions autoUpdating2];
a.block();
a2.block(); // NPE here since dispatch_once2 is skipped
}