• 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: Multiple Threaded Windows
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple Threaded Windows


  • Subject: Re: Multiple Threaded Windows
  • From: Chris Hanson <email@hidden>
  • Date: Fri, 10 Oct 2003 13:13:49 -0500

On Friday, October 10, 2003, at 08:55 AM, Chris Scharver wrote:
Also, threads are flows of execution. Objects do not "live" in any particular thread, they live in a task (address space). So just because one thread created an object does not mean that object "belongs" to the thread.

I meant only to indicate that the windows and views are created in the threads, and therefore functions called from main to do not directly access any of those objects.

This is just my point: Objects do not live in threads. They are not "created in the threads," as you say. They are created *in* the task -- in the address space of the process. They are created *by* a thread -- a flow of execution of the process.

This is vitally important to understand. The first thread (thread #1) created in a process is the "main thread." It is the thread that sets up a run loop connected to the WindowServer, which is where events come in. If you create thread #2 and create a window from within it, the window *will not* receive events in thread #2. Events for that window will be sent by the WindowServer to the run loop managed by thread #1, just like all other events.

This is slightly complicated by the fact that every NSThread does get its own run loop and autorelease pool. However, you should not take this to mean that [objectCreatedInThread2 doSomething] will result in doSomething being sent *on thread 2*. It will be sent on thread #1 if that's where you're sending it from. Or thread #3. Or thread #5...

Similarly, drawing of dirty views takes place in the main thread since it's also driven as part of the main thread's run loop. Every dirty view will be sent -drawRect: on the main thread; you have to use alternative mechanisms if you want to do drawing on secondary threads. These are described in the document "Using the Application Kit from Multiple Threads" on Apple's developer web site (part of the threading docs I've already pointed to).

-- Chris

--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Mac OS X Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Multiple Threaded Windows (From: Chris Scharver <email@hidden>)

  • Prev by Date: Re: how to warn users of wrong system
  • Next by Date: Re: how to warn users of wrong system
  • Previous by thread: Re: Multiple Threaded Windows
  • Next by thread: Re: Multiple Threaded Windows
  • Index(es):
    • Date
    • Thread