Re: Implementing a "Synchronous Channel" with dispatch
Re: Implementing a "Synchronous Channel" with dispatch
- Subject: Re: Implementing a "Synchronous Channel" with dispatch
- From: Kyle Sluder <email@hidden>
- Date: Wed, 14 Sep 2011 10:18:16 -0700
On Wed, Sep 14, 2011 at 9:38 AM, Andreas Grosam <email@hidden> wrote:
> A "Synchronous Channel" (or Synchronous Queue) is a well known pattern used in multithreading. Basically, it is used to "hand off" objects from one thread to another, with the requirement that the "producer" waits until a "consumer" took the object.
If you want to block the producer until its object is consumed, why
not use dispatch_sync?
void producer() {
while (1) {
dispatch_sync(consumer_queue, ^{
dispatch_async(consumer_queue, ^{
// consume the thing
}
}
}
}
--Kyle Sluder
_______________________________________________
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