RE: close on USB serial port hangs (read pending) on Snow Leopard
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Thread-index: Acqw1aX8L3QVgbutSl29sUWea9a53gADDW5A Thread-topic: close on USB serial port hangs (read pending) on Snow Leopard Might I suggest not doing a blocking read. Then when you need to close the port, set a flag that tells the thread it needs to end. Then when the thread has terminated, close the port. -----Original Message----- From: darwin-dev-bounces+matt=qwizdom.com@lists.apple.com [mailto:darwin-dev-bounces+matt=qwizdom.com@lists.apple.com] On Behalf Of darwin-dev-request@lists.apple.com Sent: Thursday, February 18, 2010 12:05 PM To: darwin-dev@lists.apple.com Subject: Darwin-dev Digest, Vol 7, Issue 25 Send Darwin-dev mailing list submissions to darwin-dev@lists.apple.com To subscribe or unsubscribe via the World Wide Web, visit http://lists.apple.com/mailman/listinfo/darwin-dev or, via email, send a message with subject or body 'help' to darwin-dev-request@lists.apple.com You can reach the person managing the list at darwin-dev-owner@lists.apple.com When replying, please edit your Subject line so it is more specific than "Re: Contents of Darwin-dev digest..." Today's Topics: 1. close on USB serial port hangs (read pending) on Snow Leopard (Fritz Anderson) ---------------------------------------------------------------------- Message: 1 Date: Thu, 18 Feb 2010 13:31:49 -0600 From: Fritz Anderson <fritza@manoverboard.org> Subject: close on USB serial port hangs (read pending) on Snow Leopard To: "darwin-dev@lists.apple.com list" <darwin-dev@lists.apple.com> Message-ID: <F2CD52CE-1D55-4260-AE9B-968FF7ABA22E@manoverboard.org> Content-Type: text/plain; charset=windows-1252 I have an application (compiled against the 10.4 Universal SDK, GCC 4.0) that hangs upon close() on a serial port when running on 10.6, but not on earlier OSes. There is a blocking read() pending on the file descriptor in another thread. The device is an FTDI USB-to-serial port discovered through the IO registry as kIOSerialBSDRS232Type and opened on its callout /dev entry. I create a thread (using the Cocoa NSThread API) on which I make a blocking read(). The close() is called on the main thread. The close() never returns, and the Xcode debugger can't break into the application. A sample of the hung application is at the end of this message. The NOCANCEL part of the read() implementation is suggestive to me, but I don't know what to do about it. Opening is done as: inputHandle = open([inputPath fileSystemRepresentation], O_RDWR | O_NOCTTY | O_NONBLOCK); There is no relevant entry in the "All Messages" mode of Console.app. This worked on 10.3 (no longer supported), 10.4, and 10.5. The hang occurs on 10.6. The close() is done upon application shutdown, so I suppose I could just skip it, but that's unclean, and inhibits reuse of my code. I've Googled various combinations of FTDI, read, close, read$NOCANCEL, and hang, and if there was any help, it was buried in the noise. I dug up the Kernel (etc.) release notes for Snow Leopard, and didn't find anything related to BSD I/O. Asking the doc window for "read release notes," "BSD release notes," etc., yielded nothing obvious. I'm sure I'm doing something wrong that was caught with the revised system, but I don't know where to begin. Will someone please point me the right way, either technique or document? - F ==== Sampling process 19076 for 3 seconds with 1 millisecond of run time between samples Sampling completed, processing symbols... Analysis of sampling AuthPayX (First Data) Demo (pid 19076) every 1 millisecond Call graph: 2618 Thread_804995 DispatchQueue_1: com.apple.main-thread (serial) 2618 start 2618 _start 2618 main 2618 NSApplicationMain 2618 -[NSApplication run] 2618 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] 2618 _DPSNextEvent 2618 _NSHandleCarbonMenuEvent 2618 _HandleMenuSelection 2618 _HandleMenuSelection2 2618 MenuSelectCore(MenuData*, Point, double, unsigned long, OpaqueMenuRef**, unsigned short*) 2618 FinishMenuSelection(SelectionData*, MenuResult*, MenuResult*) 2618 SendMenuItemSelectedEvent 2618 SendMenuCommandWithContextAndModifiers 2618 SendHICommandEvent(unsigned long, HICommand const*, unsigned long, unsigned long, unsigned char, void const*, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**) 2618 SendEventToEventTarget 2618 SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) 2618 DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) 2618 NSSLMMenuEventHandler 2618 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] 2618 -[NSMenuItem _internalPerformActionThroughMenuIfPossible] 2618 -[NSMenu _internalPerformActionForItemAtIndex:] 2618 -[NSMenu performActionForItemAtIndex:] 2618 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] 2618 -[NSMenuItem _corePerformAction] 2618 -[NSApplication sendAction:to:from:] 2618 -[NSApplication terminate:] 2618 -[NSNotificationCenter postNotificationName:object:] 2618 -[NSNotificationCenter postNotificationName:object:userInfo:] 2618 _CFXNotificationPostNotification 2618 __CFXNotificationPost 2618 _nsnote_callback 2618 -[AppController applicationWillTerminate:] 2618 -[I3010Terminal dealloc] 2618 -[SerialPort close] 2618 close 2618 Thread_805034 DispatchQueue_2: com.apple.libdispatch-manager (serial) 2618 start_wqthread 2618 _pthread_wqthread 2618 _dispatch_worker_thread2 2618 _dispatch_queue_invoke 2618 _dispatch_mgr_invoke 2618 kevent 2618 Thread_805059 2618 thread_start 2618 _pthread_start 2618 __CFSocketManager 2618 select$DARWIN_EXTSN 2618 Thread_805283 2618 thread_start 2618 _pthread_start 2618 __NSThread__main__ 2618 -[NSThread main] 2618 -[AbstractPort readLoop:] 2618 -[SerialPort blockingRead:size:] 2618 read$NOCANCEL$UNIX2003 Total number in stack (recursive counted multiple, when >=5): Sort by top of stack, same collapsed (when >= 5): close 2618 kevent 2618 read$NOCANCEL$UNIX2003 2618 select$DARWIN_EXTSN 2618 Sample analysis of process 19076 written to file /dev/stdout ------------------------------ _______________________________________________ Darwin-dev mailing list Darwin-dev@lists.apple.com http://lists.apple.com/mailman/listinfo/darwin-dev End of Darwin-dev Digest, Vol 7, Issue 25 ***************************************** _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Matthew Owings