Threading and NSPort retain count question
Threading and NSPort retain count question
- Subject: Threading and NSPort retain count question
- From: James Walker <email@hidden>
- Date: Thu, 17 Sep 2009 17:39:26 -0700
In the "Threading Programming Guide", I'm trying to understand the
discussion of communicating between threads using run loops and
NSMachPort objects. (Before someone asks why I'm not looking at an
easier way to pass messages between threads: I need to run on Tiger.)
I'm confused about a retain count issue.
The setup code in the main thread (Listing 3-12) creates a port with
[NSMachPort port]. This port is installed on the run loop (does the run
loop retain the port?) and then passed to the worker thread. The worker
thread function (Listing 3-14, +LaunchThreadWithPort:) takes that port
and passes it to a method sendCheckinMessage of a newly created worker
object. In sendCheckinMessage (Listing 3-15), the worker object retains
the port, and uses it as a send port for a message. Now here's the part
that confuses me: When control returns to Listing 3-14, the port gets
released. Why? This class method didn't retain or create the port, so
it shouldn't be releasing it, no?
--
James W. Walker, Innoventive Software LLC
<http://www.frameforge3d.com/>
_______________________________________________
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