[Quickfix-developers] Usage of non-threadsafe C functions in QF
Brought to you by:
orenmnero
From: Joerg T. <Joe...@ma...> - 2003-04-03 08:48:30
|
Hi, inspired by Barry Bishops core dumps on a fast multiprocessor Solaris machine, I just checked if QF used functions which have re-entrant equivalents on Solaris or Linux (suffixed by _r). Here is what I found: ./include/FieldTypes.h: *static_cast < tm* > ( this ) = *gmtime( &sec ); ./include/FieldTypes.h: *static_cast < tm* > ( this ) = *localtime( &time ); ./include/FieldTypes.h: *static_cast < tm* > ( this ) = *gmtime( &t ); ./src/C++/FieldTypes.h: *static_cast < tm* > ( this ) = *gmtime( &sec ); ./src/C++/FieldTypes.h: *static_cast < tm* > ( this ) = *localtime( &time ); ./src/C++/FieldTypes.h: *static_cast < tm* > ( this ) = *gmtime( &t ); ./src/C++/Utility.cpp: buf = gethostbyname( name ); ./src/C++/Utility.cpp: return inet_ntoa( **paddr ); The last function probably does not count, since the man page states that the returned buffer is in a thread local data space (and the _r variant is not mentioned in the man pages). BUT: The other function can really account for some core dumps. Actually we used all these function in our software until some release consistently core dumped on our fast multiprocessor production machine. As a quick fix we used the pbind command to assign only one processor to the process. Analysis of the core file revealed the culprits listed above. After replacing the usage of gmtime(), localtime() and gethostbyname() by their _r variants, core dumping stopped and all went fine since then. Oren, I have no way to check whether the functions on Windows are thread safe by default. But I would suggest to put these functions also into Utility.cpp and perhaps protect the Windows variants by a mutex if they are unsafe. If you need an example for the UNIX implementation, I could extract one out of our code. Cheers, Jörg -- Joerg Thoennes http://macd.com Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH Fax : +49 (0)241 44597-10 Lothringer Str. 52, D-52070 Aachen |