• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: starting cocoa in different thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: starting cocoa in different thread


  • Subject: Re: starting cocoa in different thread
  • From: glenn andreas <email@hidden>
  • Date: Thu, 25 Oct 2007 14:07:23 -0500


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:
This email sent to email@hidden


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

  • Prev by Date: Re: problem with NSString, UTF8, pathnames
  • Next by Date: Re: problem with NSString, UTF8, pathnames
  • Previous by thread: starting cocoa in different thread
  • Next by thread: Binding popup button to User Defaults 'sometimes' doesn't work
  • Index(es):
    • Date
    • Thread