hangs in flockfile() during fread() or fclose()
hangs in flockfile() during fread() or fclose()
- Subject: hangs in flockfile() during fread() or fclose()
- From: Paul Smith <email@hidden>
- Date: Wed, 09 Jul 2014 20:05:12 -0400
- Organization: GNU's Not UNIX!
I'm working on a massively multithreaded application (often there are 30
or more threads) which runs on GNU/Linux, Mac OSX, and Windows. I've
been having a problem which only appears on Mac OSX, that I can't
understand.
I've seen it on various (relatively up to date) MacOSX versions; for
example my latest instantiation happened here:
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.9.2
BuildVersion: 13C64
What happens is that my application hangs forever. When I attach with
the debugger or force a core dump, the hang is happening in flockfile():
Thread 14 (core thread 13):
#0 0x00007fff8a997746 in __psynch_mutexwait ()
#1 0x00007fff88cd7779 in _pthread_mutex_lock ()
#2 0x00007fff856c0edd in flockfile ()
#3 0x00007fff856c2c06 in fread ()
#4 0x0000000101fa1eb5 in Stream::load (this=0x1150d9930, fileName=<unavailable>) at /Users/build/src/Stream.cpp:182
...
I've seen this same thing happen on an fclose(), although from a
different function and for a different file. In both cases just sits
there waiting for the lock, which is never released.
Now, I have checked my code and I never invoke flockfile() myself, so
it's only ever invoked as a side-effect of the stdio functions in libc
(I've gotten a copy of the source code for libc and looked in the
implementation from the FreeBSD directory).
Further, as you can see above I'm passing in the filename to the
function, not a FILE*, and the function calls fopen(), then fread() in a
loop, then fclose() and never passes the file pointer to any other code;
basically:
void Stream::load(const char* fileName)
{
FILE* file = fopen(fileName, "rb");
if (!file) {
throw Exception(...);
}
Buffer buffer;
for (size_t n; (n = fread(buffer, 1, buffer.size(), file)) > 0;) {
append_to_local(buffer, n);
}
fclose(file);
}
I'm really confused about this. Google doesn't seem to be helping.
Does anyone have any thoughts or ideas of where to turn or how to
proceed?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden