Re: Locks
Re: Locks
- Subject: Re: Locks
- From: Ken Thomases <email@hidden>
- Date: Tue, 06 Dec 2011 23:10:04 -0600
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@hidden)
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:
This email sent to email@hidden
- Follow-Ups:
- Re: Locks
- From: Jean-Daniel Dupas <email@hidden>
References: | |
| >Locks (From: koko <email@hidden>) |
| >Re: Locks (From: Conrad Shultz <email@hidden>) |
| >Re: Locks (From: koko <email@hidden>) |
| >Re: Locks (From: "Stephen J. Butler" <email@hidden>) |
| >Re: Locks (From: Don Quixote de la Mancha <email@hidden>) |