Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: starting cocoa in different thread




On Oct 25, 2007, at 1:23 PM, Robert Nikander wrote:

Hi,

For reasons I won't go into (unless you are interested) I want to start Cocoa on a thread that is not the main posix thread. I wrote the small test program below that creates a little window with a button in it. There is a variable 'BOOL use_thread' in the main function. If it is 'NO', then the program runs fine -- I can can click the button, see that events are being generated. If use_thread = YES, then it doesn't work -- sendEvent: gets called constantly with null NSEvent pointers.

I thought I would be able to use any pthread as the "main" Cocoa event thread, as long as that thread called [NSApplication sharedApplication], set up the UI, and called [NSApp run]. Is that possible? If so, how?

Short answer is "No, it's not documented to work".

Things like performSelectorOnMainThread quite possibly use pthread_main_np() which would tie it to the "real" main thread, as well as further funky stuff about where events go (as you've seen). In fact, a bit of searching reveals that CFRunLoop hard codes in pthread_main_np to detect if the current run loop is the main run loop (or, more accurately, if pthread_main_np then CFRunLoopGetCurrent () returns CFRunLoopGetMain()).






Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium2 | build, mutate, evolve, animate | images, textures, fractals, art



_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >starting cocoa in different thread (From: Robert Nikander <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.