On Monday, August 11, 2008, at 09:56AM, "Michael Ash" <[EMAIL PROTECTED]> wrote: >On Mon, Aug 11, 2008 at 10:07 AM, Trygve Inda <[EMAIL PROTECTED]> wrote: >> I am using NSConditionLock in Cocoa but it seems unable to match the >> capabilities of MPQueue for my needs. >> >> I am using >> >> -- from my worker thread, do something on the main thread -- >> >> [lock lockWhenCondition:kTaskComplete]; >> >> In the Carbon version I used MPWaitOnQueue. >> >> The difference is that MPWaitOnQueue can wait for any signal to be received. >> I need to wait on either kTaskComplete or kTaskAbort >> >> With MPQueue I could send either kTaskComplete or kTaskAbort, but with >> NSConditionLock I can only wait on a single condition. >> >> Is there some other method that will let me block on "A or B" ? > >You could use a separate flag, and use the NSConditionLock to simply >signal whenever the separate flag's value changes. This will have the >consequence of waking up a waiting thread for all changes, not just >the ones it cares about, but if you put it in a loop then it will go >right back to sleep again.
You can also use NSCondition for this, although it's apparently buggy pre-10.5. It allows you to wake the thread up and check whatever flag(s) you care about, so I find it a bit more flexible than NSConditionLock. >You may also be able to do this more directly using pthread primitives >rather than Cocoa's classes. I don't see anything that *directly* has >the semantics you describe, but rest assured that it's possible to >build them, because the MP library is built on top of the pthread >calls. Maybe pthread_cond_wait/pthread_cond_signal? That's the closest thing I know of, and conditions are fairly straightforward to use; just make sure to check the return value from pthread_cond_wait/pthread_cond_timedwait. -- Adam _______________________________________________ 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 [EMAIL PROTECTED]