Re: Multithread, Window, Event, Runloop, ... => Headache
Re: Multithread, Window, Event, Runloop, ... => Headache
- Subject: Re: Multithread, Window, Event, Runloop, ... => Headache
- From: Ken Thomases <email@hidden>
- Date: Fri, 18 Feb 2011 20:10:41 -0600
On Feb 17, 2011, at 8:48 AM, Marco Antognini wrote:
> But now I'm stuck with a problem : is there any way to create/destroy window/view, make them live (e.g. rendering process) and get event notification; all that only in a worker thread (like we can do on Linux or Windows) ?
Short answer: no.
To the Mac frameworks, the main thread is special. The main thread is always the original thread of the process. You can't designate which thread is the main thread.
One can poke around in the Darwin sources to see that the non-portable pthread_main_np() function is determined as the C library initializes itself, and further that CFRunLoopGetMain() and similar functions rely on it.
Also, some of the frameworks install run loop sources on the current thread's run loop when they are loaded. For a typical program, they are loaded when the executable is loaded when there is only the main thread. So, their run loop sources are only processed on the main thread.
I think your best bet is to reserve the main thread for running the standard main application event loop and spawn a secondary thread to run the work of the client of your library. I realize this is a cumbersome requirement on both you and the clients of the library. Sorry I don't have better news.
Regards,
Ken
_______________________________________________
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