Re: Anything I should know about thread safety and fprintf?
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com I keep running into an apparent deadlock within fprintf. I can semi-reliably reproduce it within my application, but have been totally unable to reduce the problem to a smaller test case. In a nutshell, I have two threads calling this - fprintf(stderr, "%s:%d - %s\n", [fileBaseName cStringUsingEncoding:NSASCIIStringEncoding], lineNumber, [formattedMessage cStringUsingEncoding:NSASCIIStringEncoding]); resulting in the following stack trace. The first thread just sits in write$NOCANCEL$UNIX2003() for ever. thread A : #0 0x94709a36 in write$NOCANCEL$UNIX2003 () #1 0x9470998e in _swrite () #2 0x947098bb in __sflush () #3 0x946d4ac8 in __vfprintf () #4 0x94709603 in vfprintf_l () #5 0x94709597 in fprintf () thread B : #0 0x946d392e in semaphore_wait_signal_trap () #1 0x946db405 in pthread_mutex_lock () #2 0x94713383 in flockfile () #3 0x947095e6 in vfprintf_l () #4 0x94709597 in fprintf () -- Terry _______________________________________________ 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... On Jan 23, 2008, at 11:48 AM, Jonathan del Strother wrote: This is thread A blocked waiting for a write to complete, because it's writing to a pipe, socket, network file over a protocol for which the server is not currently responding, or other blocking operation. While it's waiting for this write to complete, it's holding a serialization lock on the stdio FILE that it's writing to. This is thread B blocking waiting to acquire the lock currently held by thread A. You need to figure out why thread A is blocking. Why it's blocking will depend on what type of thing the underlying descriptor for the FILE * being written happens to be attached to. This will most likely boil down to a network connectivity problem, a server problem, or a problem with another program that you are trying to talk to over a pipe/UNIX domain socket/whatever (i.e. a bug in your code). This email sent to site_archiver@lists.apple.com
participants (1)
-
Terry Lambert