------- Additional Comments From redi at gcc dot gnu dot org 2004-10-11 12:22 ------- I've been thinking about this PR, probably too much. I assume my concerns are unfounded, or we'd have noticed bigger problems by now, but here goes:
The change to gthr-posix.h means that if GCC is configured with thread-support on Tru64 then it _always_ compiles thread-safe programs, even when -pthread is not used. The only way to prevent that is to configure with --disable-threads. Carlo said in comment #25 that this means even single-threaded apps will use slower, reentrant versions of libs. For system libs, this is not true, because if -pthread is not given then the reentrant libs won't be linked to, even though _REENTRANT was defined. Is it even well-formed to define _REENTRANT and include <pthread.h> but _not_ link to the reentrant libs? Tru64's <pthread.h> (at least, the fixincluded version) says: * You should always define _REENTRANT on the command line, usually by using * "cc -pthread" or "cxx -pthread", to be sure that it will be available for * all header files. This recommendation is not followed by gthr-posix.h, which defines _REENTRANT only before including <pthread.h>. Not all libstdc++ headers include gthr-posix.h, so _REENTRANT won't always be defined e.g. <utility> doesn't include gthr-posix.h, so in this code: #include <utility> #include <unistd.h> #include <iostream> _REENTANT will not be defined when unistd.h is included. The above comment from Tru64's pthread.h is followed by "#include <unistd.h>" which will have no effect if that file was already included before _REENTRANT was defined. Rainer's proposal to put _REENTRANT in os_defines.h will ensure that _REENTRANT is always defined, but it won't get around the issue of including thread-safe definitions but not linking to them (but maybe that's a non-issue). Would it be possible to only include <pthread.h> if _REENTRANT is defined, and include some <pthread-dummy.h> otherwise, which just has dummy decls for the pthread_xxx() functions needed by gthreads? That way whether reentrant code is used would depend on whether -pthread was used, as is intended. I have very litle experience with either MT or Tru64, so probably haven't got this analysis right, I'm just trying to understand the issues better. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11953