Re: Mixing Obj-C and C "methods"
Re: Mixing Obj-C and C "methods"
- Subject: Re: Mixing Obj-C and C "methods"
- From: Jean-Daniel Dupas <email@hidden>
- Date: Wed, 07 Aug 2013 18:52:24 +0200
Le 7 août 2013 à 18:34, Andy Lee <email@hidden> a écrit :
> 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.
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 (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