Le 7 août 2013 à 18:34, Andy Lee <ag...@mac.com> a écrit : > 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.
And even with a synchronous API, the TLS approach is fragile as the API as to guarantee that the callback is performed on the same thread. But honestly, if I encounter such API and it does not let me pass a context pointer for the callback, I will just avoid it and use something else. >> 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 > -- Jean-Daniel _______________________________________________ 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