Re: Mixing Obj-C and C "methods"
Re: Mixing Obj-C and C "methods"
- Subject: Re: Mixing Obj-C and C "methods"
- From: Andy Lee <email@hidden>
- Date: Wed, 07 Aug 2013 12:34:49 -0400
On Aug 7, 2013, at 12:04 PM, Jean-Daniel Dupas <email@hidden> 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 (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