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 11:13:09 -0700
On Wed, Sep 14, 2011 at 11:00 AM, Dave Zarzycki <email@hidden> wrote:
> Dispatch queues exist to solve both the synchronous and asynchronous producer/consumer pattern. If you want the producer to wait until the consumer is done, then use dispatch_sync() instead of dispatch_async():
>
> x = create_something();
> dispatch_sync(consumer_q, ^{
> do_something_with(x);
> });
> // do_something_with() is done
>
> That's it. Easy, huh? :-)
I think the point is to wait until the _handoff_, not necessarily
until the consumer is finished _consuming_. For example, the producer
can work on producing the next object to be consumed while the
consumer is consuming the previous one.
I think using the dispatch_sync(some_q, ^{ dispatch_async(some_q,
^{}); }) technique accomplishes that.
--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