Configuring a Port-based Input Source -- Part 1
Configuring a Port-based Input Source -- Part 1
- Subject: Configuring a Port-based Input Source -- Part 1
- From: John Love <email@hidden>
- Date: Mon, 26 Jan 2009 08:55:15 -0500
I have this request for help in two parts, because I've been bumped
due to length:
Reference: "Configuring a Port-Based Input Source" of
http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/chapter_6_section_5.html#/
/apple_ref/doc/uid/10000057i-CH16-SW7
My challenge is to try to understand this part of Chapter 5 of Apple's
"multithreading.pdf". My single question is "Is my understanding
correct?" .. and the best way I can approach this is to go almost line-
by-line of the code presented.
First and foremost, I understand that a NSMachPort is a two way port:
for the main thread, the "remote" port is the background port and for
the background Thread, the "remote" port is the main port. In short,
the same port is used for two-way communication.
I have placed all the methods listed in this section of Ch. 5 are in a
separate controller, ThreadController, from here on called "TC". So,
when I call any of these methods from the main thread, I use:
[iboTC somePortMethod];
My principal variation to Apple's code involves calling –launchThread
with a passed parm, i.e.:
[iboTC launchThread:self];
Within my TC's – (void) launchThread:(id)theMainCtrl, I assign the
passed parm to my TC instance variable = mainCtrl (for use later, as
you will see).
So, going almost line-by-line:
Within Apple's –launchThread, they have:
NSPort* myPort = [NSMachPort port];
This appears to be a new background Port. Is it, or is it a new local
main Port? I think it is a background Port because Apple continues by
calling – detachNewThreadSelector with an object equal to this Port.
Within the selector passed to –detachNewThreadSelecctor:
+(void)LaunchThreadWithPort:(id)inData
(actually, I convert it to an instance method - don't know why Apple
uses a class method here
?)
the passed inData is immediately converted:
NSPort* distantPort = (NSPort*)inData;
Where their distantPort, or remote Port, is the remote Port for the
main Thread, thus making the passed Port the background Port.
Am I good so far and if not, why not?
[continued in Part II]
_______________________________________________
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