Date: 2002-12-18 09:07:27
continuing on with the "Deadlocking problems with recursive_mutex on Linux
with boost 1.29.0" thread, started by Beat Schaer on the 4th of this month;
I've come across the same issue on RedHat Linux 7.3 using gcc 2.96 but not
using gcc 3.0.4.
The main point of the issue seems to be a hang over from a previous version
of Linux Threads where invoking pthread_mutexattr_setkind_np with
PTHREAD_MUTEXATTR_RECURSIVE_NP was the only way to set a recursive mutex.
In /usr/include/pthread.h PTHREAD_MUTEXATTR_RECURSIVE_NP is still defined
but pthread_mutexattr_setkind_np is not and is only defined as a weak symbol
in libpthread (from glibc-devel-2.2.5-40).
The correct mutex attribute, PTHREAD_MUTEXATTR_RECURSIVE, is conditionalised
in /usr/include/pthread.h via the __USE_UNIX98 macro, which is set, in turn,
if _XOPEN_SOURCE is defined and has a value >= 500, when
/usr/include/features.h is defined and which is not present in a default
invocation of gcc, but is present and defined in gcc3.
Ideally, the workaround for this should reside in
$BOOST_ROOT/config/platform/linux.hpp but due to /usr/include/features.h
being included prior to the platform header file, I've devised a work-around
for $BOOST_ROOT/config/compiler/gcc.hpp as follows.
*** gcc.hpp Wed Dec 18 13:59:59 2002
--- gcc.hpp.ORIG Wed Dec 18 13:59:56 2002
*** 57,67 ****
# warning "Unknown compiler version - please run the configure tests
and report the results"
- #if defined(__linux) || defined(__linux__) || defined(linux)
- #if defined(__GNUC__) && __GNUC__ < 3
- #if !defined(_XOPEN_SOURCE)
- #define _XOPEN_SOURCE 500
--- 57,59 ----
Prior to applying the patch, the sample program
$BOOST_ROOT/libs/thread/example/recursive_mutex.cpp hangs when acquiring a
recursive mutex for the first time; after applying the patch, the sample
program works as advertised on the accompanying documentation page(s).
Obviously this will need a lot more testing on other Linux distros and with
other platforms which use gcc but this is a first step ...
All the best
-- Gary Gale Mail: gary_gale_at_[hidden] Senior Software Engineer Phone: +44 (0)1296 617195 Network Associates - Your Network, Our Business Web: www.nai.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk