• 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: NSConditionLock vs MPQueue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSConditionLock vs MPQueue
      • From: "Adam R. Maxwell" <email@hidden>
References: 
 >NSConditionLock vs MPQueue (From: Trygve Inda <email@hidden>)

  • Prev by Date: Re: NSImage and zooming PDFs vs. bitmaps
  • Next by Date: Re: Get specified window from nib
  • Previous by thread: NSConditionLock vs MPQueue
  • Next by thread: Re: NSConditionLock vs MPQueue
  • Index(es):
    • Date
    • Thread