JNF performOnMainThreadWaiting thread safety

David DeHaven david.dehaven at oracle.com
Tue Feb 19 09:15:55 PST 2013


In my experience the "performOnMainThread" calls are all thread safe (that's their intended use…), I would expect the JNF message to be a wrapper for NSObjects performSelectorOnMainThread:withObject:waitUntilDone:. There's no guarantee of order (unless multiple calls are made in the same thread) or that the request will be processed in any timely manner, so the calling threads need to consider the implications of blocking until the request is handled and the main thread needs to be in running it's main runloop.

-DrD-

> Hello, Leonid. 
> 
> The following is just my speculation, so it might be not true.
> 
> The JNFRunLoop reference does not state if this method is thread-safe or not, however it should probably be implemented by NSObject performOnMainThreadWaiting method. And NSObject is thread-safe according to the documentation.
> 
> So I think that it is much more likely to be thread-safe than not. 
> However, only someone how've seen the implementation of the JNFRunLoop would be 100% sure. 
> 
> With best regards. Petr. 
> 
> 
> On Feb 19, 2013, at 5:22 AM, Leonid Romanov wrote:
> 
>> Hi,
>> I've got a question: is + (void)performOnMainThreadWaiting:(BOOL)waitUntilDone withBlock:(void (^)())block thread safe? Suppose two native threads are calling this method with waitUntilDone set to YES.  Should we be OK in this case or some external locking is necessary to ensure that both threads won't call performOnMainThreadWaiting at the "same" time?
>> 
>> Thanks,
>> Leonid.
> 



More information about the macosx-port-dev mailing list