Re: OSIncrementAtomic(), lck_mtx_lock() interoperability.
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com On Nov 15, 2006, at 2:04 PM, Matt Darland wrote: For the most part, no. -- Terry _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... If I have an integer value X that is usually incremented through OSIncrementAtomic, but in occasional cases I'm holding a mutex (via lck_mtx_lock) to a structure that contains X, and I want to increment X: Can I just ++X while holding the mutex and avoid also having to call OSIncrementAtomic in those rare cases? i.e. Do OSxxxAtomic and lck_mtx_xxx enforce the same memory coherency with respect to an integer? The value is not guaranteed to be updated in other CPU caches until after a memory barrier, if the operation is not itself an atomic one, and on x86, there is no guarantee that an unlock will result in a memory barrier (it depends on strong write ordering, and the fact that no one else is permitted to write a lock that's locked in order to do the unlock operation). Unless your operation is protected by the same lock in all cases, there's no reliable guarantee. There's ways to order code to usefully use a barrier only on a 1->0 on a release (for example), and use Atomic operations everywhere, but the converse is not true. This email sent to site_archiver@lists.apple.com
participants (1)
-
Terry Lambert