Re: NSConditionLock vs MPQueue
Re: NSConditionLock vs MPQueue
- Subject: Re: NSConditionLock vs MPQueue
- From: "Michael Ash" <email@hidden>
- Date: Mon, 11 Aug 2008 12:56:26 -0400
On Mon, Aug 11, 2008 at 10:07 AM, Trygve Inda <email@hidden> 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 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.
Mike
_______________________________________________
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