Mon 05 Dec 2011 11:50:18 PM UTC, comment #9:
Solaris is SunOS 5, so no, it's not a SunOS 4 thing, and I doubt threading was the same going back that far (and I think we can safely consider that going back farther than necessary).
I have not personally had any problems putting it only in PTHREAD_CFLAGS, but I may have thought libtool included CFLAGS in that link step.
-- Scott
|
Fri 02 Dec 2011 08:17:07 PM UTC, comment #8:
My concern is the redundancy of specifying -D_REENTRANT with cc+"-mt" or gcc+"-pthreads", as well as cc+"-lpthread", and the lack of "-mt" in PTHREAD_LIBS.
There is this note in the macro:
# On Solaris (at least, for some versions), libc contains stubbed
# (non-functional) versions of the pthreads routines, so link-based
# tests will erroneously succeed. [...] So,
# we'll just look for -pthreads and -lpthread first:
Does anyone here know what versions of Solaris this applies to? Is this a SunOS4 thing?
|
Fri 02 Dec 2011 03:32:37 PM UTC, comment #7:
I've used the patch for years in my software packages without any trouble, but I would say the only possible improvement is detecting that it's "that" compiler on Solaris. I don't know what the convention is for that or if you have one. Maybe just checking for "CC" is enough. I use the "if gcc" check because I haven't encountered anything there but gcc and Sun's.
-- Scott Cantor
|
Fri 02 Dec 2011 03:15:44 PM UTC, comment #6:
I'm wondering about the state of this patch, because I'd like to release a new version of the archive soon. Is that change to AX_PTHREAD considered all right the way it is, or does anyone object?
|
Tue 22 Nov 2011 01:08:46 AM UTC, comment #5:
Sounds about right. From the (Solaris 8) CC(1) man page...
-mt Compile and link for multithreaded code.
This option:
o Passes -D_REENTRANT to the preprocessor
o Passes -lthread in the correct order to ld
o Ensures that, for standard mode (the default
mode), libthread is linked before libCrun
o Ensures that, for compability mode (-compat),
libthread is linked before libC
The -mt option is required if the application or
libraries are multithreaded.
Warnings:
You must use this option, rather than -lthread.
If you are using POSIX threads, you must link with
the options -mt -lpthread. The -mt option is
necessary because libC (compatibility mode) and
libCrun (standard mode) need libthread for a mul-
tithreaded application.
|
Tue 22 Nov 2011 12:22:48 AM UTC, comment #4:
Usually omitting -mt doesn't matter that much for C applications, but it triggers different startup code for C++ applications that ensures the right ordering of static constructors and so forth in conjunction with the threading routines.
If you have a preferred test for which compiler is involved, that's fine, as long as -mt is added for Solaris Studio.
|
Mon 21 Nov 2011 11:33:57 PM UTC, comment #3:
> What does PTHREAD_CFLAGS and PTHREAD_LIBS return without this patch?
On both a 64-bit Solaris 8 system, and a 64-bit/AMD64 Solaris 10 system here:
PTHREAD_CC = cc
PTHREAD_CFLAGS = -D_REENTRANT
PTHREAD_LIBS = -lpthread
But then, things aren't as simple as they seem. From the cc(1) man page:
-mt Passes D_REENTRANT to preprocessor. Appends -lthread.
If you are doing your own multithread coding, you must
use this option in the compile and link steps. To
obtain faster execution, this option requires a mul-
tiprocessor system. On a single-processor system, the
resulting executable usually runs more slowly with this
option.
So potentially, for the Solaris compiler, -D_REENTRANT is redundant and -mt is also needed in PTHREAD_LIBS...
|
Mon 21 Nov 2011 10:52:23 PM UTC, comment #2:
Pushed to the Git repository in commit 6c8eddf2606e768cea66e49fc746330ba88de18e. Thank you very much!
|
Mon 21 Nov 2011 06:35:21 PM UTC, comment #1:
Thank you very much for pointing out that problem. If you have the chance, could you please attach a proper diff/patch file to this bug report to fix the problem?
|
Thu 17 Nov 2011 12:57:22 AM UTC, original submission:
The section that adds "extra" flags for Solaris is missing the addition of the -mt option for Oracle/Sun CC. It's used at the top in the detection code, but never gets added. _RENTRANT alone is not sufficient when using that compiler with C++, you get improper safety for object startup and shutdown.
I use this in place of the existing code for special flags:
solaris)
if test "$GCC" = "yes"; then
flag="-D_REENTRANT"
else
flag="-mt -D_REENTRANT"
fi
|