メソッドのスウィズリングは次のシングルトン初期化子で使用されていますが、スウィズリングのスレッド セーフについてはわかりません。
スレッドが別のメソッドによってスウィズルされようとしているメソッドを呼び出そうとしている間に何が起こるでしょうか? そのメソッドを呼び出そうとしているスレッドがある間、いつでもスウィズルしても安全ですか? 公式の参考文献で答えてください。ありがとう
#import <dispatch/dispatch.h>
#import <objc/runtime.h>
@implementation MySingleton
static MySingleton * __singleton = nil;
+ (MySingleton *) sharedInstance_accessor
{
return ( __singleton );
}
+ (MySingleton *) sharedInstance
{
static dispatch_once_t __once = 0;
dispatch_once( &__once, ^{
__singleton = [[self alloc] init];
Method plainMethod = class_getInstanceMethod( self, @selector(sharedInstance) );
Method accessorMethod = class_getInstanceMethod( self, @selector(sharedInstance_accessor) );
method_exchangeImplementations( plainMethod, accessorMethod );
});
return ( __singleton );
}
@end