• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Locks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Locks


  • Subject: Re: Locks
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Wed, 07 Dec 2011 12:07:08 +0100

Le 7 déc. 2011 à 06:10, Ken Thomases a écrit :

> 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).
>

A better solution would be to use posix mutex and completely avoid OSSpinLock.
There is really few situations where SpinLock give you any benefit,  as mutex implementation already try to spin a couple of time before locking. So if there is no contention, they are both very cheap and fast, and if there is contention, the mutex is better as it don't consume CPU waiting for other threads.


-- Jean-Daniel




_______________________________________________

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: Andreas Grosam <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>)
 >Re: Locks (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Safari downloader-like behavior
  • Next by Date: Printing patterns
  • Previous by thread: Re: Locks
  • Next by thread: Re: Locks
  • Index(es):
    • Date
    • Thread