Thanks Dave, that's awesome! Just what I was looking for! 

Q: When a context object is set with dispatch_set_context(), is it retained? Or 
do I need to retain it first, set it, and then in the cancel handler release it?

-Jon

On Jan 5, 2011, at 11:15 AM, Dave Zarzycki wrote:

> Jonathon,
> 
> GCD is an object oriented API done in C. If you look at the man page entitled 
> dispatch_object, you'll see that one can call dispatch_set_context() and 
> dispatch_get_context() against any GCD object (sources and queues are where 
> they make the most sense). In fact, if you're simply looking for a "goodbye 
> kiss" when the last reference to a GCD object is dropped (via 
> dispatch_retain() and dispatch_release()), then your code can install a 
> finalizer via dispatch_set_finalizer_f(), which is passed the same context 
> managed by the aforementioned API.
> 
> Have fun,
> 
> davez
> 
> 
> On Jan 5, 2011, at 10:58 AM, Jonathon Kuo wrote:
> 
>> When a GCD source gets cancelled, either via dispatch_source_cancel() or 
>> because the source went away, I have no context other than the 
>> dispatch_source_t source variable. How can I know for which source a source 
>> cancel handler gets invoked? I have many simultaneous sources (sockets, 
>> files, etc) and when a source cancel handler gets called I have no idea what 
>> source it's for, so I can't do cleanup. Is dispatch_source_t queryable? Is 
>> there a way to attach a userInfo object to it? Do I have to manage this 
>> externally in a table myself?_______________________________________________
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> http://lists.apple.com/mailman/options/cocoa-dev/zarzycki%40apple.com
>> 
>> This email sent to zarzy...@apple.com
> 
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to