On Aug 7, 2013, at 12:04 PM, Jean-Daniel Dupas <devli...@shadowlab.org> wrote:
> If you intend to use it from multiple threads, so use a tls.
> 
> __thread id myCallbackHandler;

I did not know about __thread, thanks for this.  By using tls you're 
effectively having each thread store the info that would have been stored by 
the implementation of the callback's context pointer, if it had one.

If [x foo] and [y foo] are called in the same thread, then that thread's 
myCallbackHandler can still get clobbered if the callback is asynchronous.  So 
I guess you'd have to be careful to always call -foo in a separate thread, or 
implement it to always spawn a thread.

> I was talking about the case where you have to deal with a poorly design API 
> with no context pointer argument.
> The case with a context argument should off course be handle the way you 
> describe.

I see, thanks.

--Andy


_______________________________________________

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

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

Reply via email to