4 #include <objc/NSObject.h>
6 static semaphore_t go1;
7 static semaphore_t go2;
8 static semaphore_t done;
10 #define VARCOUNT 100000
12 static id vars[VARCOUNT];
15 void *destroyer(void *arg __unused)
19 for (int i = 0; i < VARCOUNT; i++) {
20 objc_destroyWeak(&vars[i]);
22 semaphore_signal(done);
27 void *deallocator(void *arg __unused)
32 semaphore_signal(done);
39 // rdar://12896779 objc_destroyWeak() versus weak clear in dealloc
41 // Clean up from previous cycle - objc_destroyWeak() doesn't set var to nil
42 for (int i = 0; i < VARCOUNT; i++) {
47 for (int i = 0; i < VARCOUNT; i++) {
48 objc_storeWeak(&vars[i], obj);
51 // let destroyer start before deallocator runs
52 semaphore_signal(go1);
54 semaphore_signal(go2);
63 semaphore_create(mach_task_self(), &go1, 0, 0);
64 semaphore_create(mach_task_self(), &go2, 0, 0);
65 semaphore_create(mach_task_self(), &done, 0, 0);
68 pthread_create(&th[1], NULL, deallocator, NULL);
69 pthread_create(&th[1], NULL, destroyer, NULL);
71 for (int i = 0; i < 100; i++) {