Re: Can I create a thread with a runloop and a dispatch queue?
Re: Can I create a thread with a runloop and a dispatch queue?
- Subject: Re: Can I create a thread with a runloop and a dispatch queue?
- From: Ken Thomases <email@hidden>
- Date: Thu, 03 Oct 2013 16:10:18 -0500
On Oct 3, 2013, at 4:04 PM, Ken Thomases wrote:
> On Oct 3, 2013, at 3:55 PM, Jens Alfke wrote:
>
>> On Oct 3, 2013, at 1:23 PM, Ken Thomases <email@hidden> wrote:
>>
>>> I'm not seeing how the above API would be easier/cleaner to implement if run loops had queues.
>>
>> Because the implementation could initially capture the current dispatch queue (by calling dispatch_get_current_queue) and then when the block is ready to be called, invoke it via dispatch_async on that captured queue. Currently this works only if the method was called from a dispatch queue, but will break if called otherwise, i.e. from normal runloop-based code, because dispatch_get_current_queue will return NULL.
>
> Well, you've gone from requesting the ability to assign a queue to a run loop to assuming that all run loops would have queues. And your code already dispatches to the calling thread's run loop, right? Why not, if dispatch_get_current_queue() returns NULL, fall back to the current approach of targeting the run loop?
Oh, and another thing: in the world as it is, if you get and retain the current queue, then it remains valid until you release it. You are assured that you can dispatch tasks to it and they will get run (barring deadlock or the like).
However, if queues are tied to threads, then what happens when the thread terminates? You're holding a reference to a queue which feeds into a defunct thread. What happens to tasks you dispatch to it?
Regards,
Ken
_______________________________________________
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