开发者

How to create an atomic function in objective-c

Is there a way to execute a whole objective-c开发者_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.


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜