views:

53

answers:

2

Is there a way to execute a whole objective-c function atomic?

As far as I know, using synchronized only protects a specific peace of code from being executed on multiple threads at the same time. But what I want is stop ALL other threads from doing ANYTHING, as long as I execute the function.

+3  A: 

Nope. Can't do that.

Or, well, you probably could if you dipped deep enough in the Mach APIs (on Mac OS X anyway).

But you shouldn't do that.

Why do you think you want to do that?

bbum
+1  A: 

There is a wealth of info in the Threading Programming Guide. It specifically mentions to avoid synchronization (which is funny, cause you cant sometimes) but they offer some suggestions around the problem.

You will have serious problems with your design if you start running your software on multicore. It is a VERY expensive operation to stop all cores from running to run your bit of code. Mutexes, semaphores, run loop events, and atomic operations are the way to go.

Brent Priddy