I did come across OSAtomicIncrementXX … thanks. I cannot use NSLock as this is in a BSD Static lib and I am required to implement as close to windows as possible.
So my code looks like below and is isomorphic to the Windows implementation. ========= LONG volatile Mylock = 0; void SetLock() { while(Mylock){Sleep(0);}; // Give up timeslice #ifndef MAC InterlockedIncrement(&Mylock); #else OSAtomicIncrement32(&Mylock); #endif } void FreeLock() { #ifndef MAC OSInterlockedDecrement(&Mylock); #else OSAtomicDecrement32(&Mylock); #endif } =========== Thanks. -koko On Dec 6, 2011, at 5:39 PM, Conrad Shultz wrote: > On 12/6/11 3:28 PM, koko wrote: >> In windows we have: >> >> LONG volatile Mylock = 0; >> InterlockedIncrement(&Mylock); >> InterlockedDecrement(&Mylock); >> >> >> What should these be replaced with for OSX as in : > > Have you read the Threading Programming Guide? > > I'm not a Windows developer, so I had to look up the MSDN docs, and > based on those it seems like you want the OSAtomicIncrementxxx (and > matching OSAtomicDecrementxxx) as direct analogues. > > However, since it sounds like you are trying to use these functions to > implement locking in a multithreaded application, perhaps you should > also examine whether higher level constructs would prove sufficient. A > couple such mechanisms you can read about are NSLock and the > @synchronized directive. GCD has some features (dispatch semaphores and > barrier blocks come to mind) that may also be helpful in certain > circumstances. > > -- > Conrad Shultz > > Synthetiq Solutions > www.synthetiqsolutions.com > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com