On Fri, Jul 10, 2009 at 6:33 PM, Julien Isorce<julien.iso...@gmail.com> wrote: > So the final question: is there a way to make [NSThread isMainThread] return > YES in a thread different that the main thread of a process, on MacOSX ?
We don't have the source for the Foundation Framework, but there is a pthreads pthread_main_np() which provides the same info. I suspect calling [NSThread isMainThread] wraps it. And even if it doesn't call this function, you'd want to make pthread_main_np() return the "right" value. So let's dig in the Libc source: int pthread_main_np(void) { pthread_t self = pthread_self(); return ((self->detached & _PTHREAD_CREATE_PARENT) == _PTHREAD_CREATE_PARENT); } So where else is _PTHREAD_CREATE_PARENT referenced? Only place I could find is in pthread_init(): __private_extern__ int pthread_init(void) { pthread_attr_t *attrs; pthread_t thread; /* ... */ thread = &_thread; /* ... */ thread->detached = PTHREAD_CREATE_JOINABLE|_PTHREAD_CREATE_PARENT; /* ... */ } Hmm... where does _thread come from? It's a static file global, set by calling _pthread_set_self(0): __private_extern__ void _pthread_set_self(pthread_t p) { extern void __pthread_set_self(pthread_t); if (p == 0) { bzero(&_thread, sizeof(struct _pthread)); p = &_thread; } p->tsd[0] = p; __pthread_set_self(p); } __pthread_set_self appears to be an ASM function, and my assembly isn't good but I'd guess it is making a syscall. And this is where I stop analyzing Libc, because it has become obvious that long before your plugin gets loaded, some other thread will have already claimed the main thread as its own. Not only does Cocoa have no support for setting another NSThread as the main thread, but I'd argue that Darwin itself forbids such a thing. It is time to give up on your quest. Why can't you use my suggestion of a separate, full Cocoa helper app that runs the GUI stuff for your plugin? _______________________________________________ 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com