Determine if an object is accessible by more than one thread?

I get sporadic accidents EXC_BAD_ACCESS, which I think are related to multithreaded problems. (I tried profiling with Zombies, but the application does not crash when profiling). So I'm wondering if there is any mechanism for debugging purposes to determine if an object will be accessible by more than one thread at a time? Maybe somehow print the log statement, if so?

+4
source share
1 answer

A simple and dirty way to report if you are the only one executing in the stream will rely on insecure static variables:

-(void)concurrentMethod { static NSThread *runningThread = nil; NSThread *myThread = [NSThread currentThread]; if (runningThread != nil) { NSLog(@"Thread %@: running concurrently with %@", runningThread, myThread); } runningThread = myThread; ... // Do the useful stuff here if (runningThread != myThread) { NSLog(@"Thread %@: pre-empted by %@", myThread, runningThread); } runningThread = nil; } 
+5
source

All Articles