Mailing Lists: Apple Mailing Lists

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

ReadPipeAsync in a Cocoa App



Hi,
I am writing a class to connect to a Garmin GPS unit (forerunner 301) and have been reading through the list archives to try and find some answers but haven't been able to find anything. In the sample project USB Simple Example it shows how to use the run loop to wait for the event, but I can't seem to conceptually understand how to work it in a multi-threaded environment where the worker thread already contains a run loop.


The current pattern I use when connecting to a device is to spin off a thread that talks to the actual device and the two threads communicate via an NSPort.

eg. (pseudo code typed in Mail)

- (id)init
{
_port = [[NSPort port] retain];
[_port setDelegate:self];
[NSThread detachNewThreadSelector:@selector (runBackgroundThread:) .....];
}


- (void)runBackgroundThread:(id)notUsed
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[[NSRunLoop currentRunLoop] addPort:_port forMode:(NSString *) kCFRunLoopCommonModes];
[[NSRunLoop currentRunLoop] run];

[pool release];
}


So the problem as I see it is that because the worker thread's runloop has the NSPort as a source, then if I were to call the runloop run/stop like in the example, it is not going to return. I'm just wanting to know how people over come this or am I missing something?

Any information is greatly appreciated.

Regards,
Greg
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Usb mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/usb/email@hidden

This email sent to 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.