patchGNU Autoconf Archive - Patches: patch #7666, ax_pthread macro fails for C++ on...


patch #7666: ax_pthread macro fails for C++ on Solaris

Submitted by:  None
Submitted on:  Thu Nov 17 00:57:22 2011  
Priority: 5 - NormalStatus: Done
Assigned to: Peter Simons <simons>Originator Email: -unavailable-
Open/Closed: Closed

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


(Jump to the original submission Jump to the original submission)

Mon Dec 5 23:50:18 2011, 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 Dec 2 20:17:07 2011, 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?

Daniel Richard G. <iskunk>
Fri Dec 2 15:32:37 2011, 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 Dec 2 15:15:44 2011, 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?

Peter Simons <simons>
Project AdministratorIn charge of this item.
Tue Nov 22 01:08:46 2011, 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.


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.

Daniel Richard G. <iskunk>
Tue Nov 22 00:22:48 2011, 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 Nov 21 23:33:57 2011, 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_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

So potentially, for the Solaris compiler, -D_REENTRANT is redundant and -mt is also needed in PTHREAD_LIBS...

Daniel Richard G. <iskunk>
Mon Nov 21 22:52:23 2011, comment #2:

Pushed to the Git repository in commit 6c8eddf2606e768cea66e49fc746330ba88de18e. Thank you very much!

Peter Simons <simons>
Project AdministratorIn charge of this item.
Mon Nov 21 18:35:21 2011, 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?

Peter Simons <simons>
Project AdministratorIn charge of this item.
Thu Nov 17 00:57:22 2011, 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:

if test "$GCC" = "yes"; then
flag="-mt -D_REENTRANT"



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):

Attached Files
file #24417:  axthreadpatch.txt added by None (715B - text/plain - My working patch is attached.)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by iskunk (Posted a comment)
  • -unavailable- added by simons (Posted a comment)
  • -unavailable- added by simons
  • -unavailable- added by simons
  • -unavailable- added by None (Submitted the item)

    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed Dec 21 10:59:10 2011simonsStatusReady For Test=>Done
    Mon Nov 21 22:52:23 2011simonsStatusNeed Info=>Ready For Test
    Mon Nov 21 19:47:57 2011NoneAttached File-=>Added axthreadpatch.txt, #24417
    Mon Nov 21 18:35:21 2011simonsStatusNone=>Need Info
      Assigned toNone=>simons
      Carbon-Copy-=>Added steven g. johnson
      Carbon-Copy-=>Added daniel richard g.

    Back to the top

    Powered by Savane 3.1-cleanup1