-
-
Save Graham--M/98750a153137872dc0a21d0ab55826d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <objc/runtime.h> | |
#import <objc/objc-arc.h> | |
#include <pthread.h> | |
/* ----- Mimimal Class ----- */ | |
__attribute__((objc_root_class)) | |
@interface Test { id isa; } | |
+ (Class)class; | |
+ (id)new; | |
- (void)dealloc; | |
- (id)autorelease; | |
- (id)retain; | |
- (void)release; | |
@end | |
@implementation Test | |
+ (Class)class { return self; } | |
+ (id)new { return class_createInstance(self, 0); } | |
- (void)dealloc { object_dispose(self); } | |
- (id)autorelease { return objc_autorelease(self); } | |
- (id)retain { return objc_retain(self); } | |
- (void)release { objc_release(self); } | |
- (void)_ARCCompliantRetainRelease {} | |
@end | |
/* ----- Test Program ----- */ | |
id ptr = NULL; // Will hold the weak reference. | |
void *thread_func(void *x_void_ptr) { | |
id obj = objc_loadWeakRetained(&ptr); | |
return NULL; | |
} | |
int main(void) { | |
Test *test = [Test new]; | |
objc_storeWeak(&ptr, test); | |
pthread_t the_thread; | |
if (pthread_create(&the_thread, NULL, thread_func, NULL)) { | |
return 1; | |
} | |
[test release]; | |
test = NULL; | |
if (pthread_join(the_thread, NULL)) { | |
return 2; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment