On Dec 6, 2011, at 10:05 PM, Don Quixote de la Mancha wrote:

> Contrary to Ken Thomases' assertion, there are all kinds of reasons to
> use atomic operations as locking primitives.  One is that they cannot
> result in process context switches; if you are certain that you will
> release the lock quite quickly, it is a whole lot faster, and uses
> less memory, to use atomic arithmetic.

You still shouldn't implement it manually using atomic increment and decrement. 
 You should use OSSpinLock if that's what you're attempting.  Which was my 
point.  The original code was horrible and horribly misguided (and suffers from 
a race condition as others have pointed out, which is virtually inevitable when 
people try to reimplement synchronization instead of using ready-made 
synchronization primitives).

Also, you'll note that the original code posted included calls to Sleep(0) 
specifically to yield processor time, so it in fact would result in process 
context switches.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to