Hi Ron,

On Mon, 20 Jul 2015 10:45:51 +0930, Ron <[email protected]> wrote:
> I was investigating why some code that probably should have built
> cleanly with this toolchain didn't, and the reason is it turns out
> to not be defining _REENTRANT when the -pthread option is passed.
> 
> Which is a little bit weirder because at first blush it looks like
> it had intended to.  Compare:
> 
>  $ gcc -dumpspecs | grep -B1 _REENTRANT
>  *cpp:
>  %{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}
> 
>  $ x86_64-w64-mingw32-gcc -dumpspecs | grep -B1 _REENTRANT
>  *cpp:
>  %{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} %{municode:-DUNICODE} 
> %{pthread:-D_REENTRANT} %{!no-pthread:-U_REENTRANT}

Add this to the mix:

$ x86_64-w64-mingw32-gcc-win32 -dumpspecs | grep -B1 _REENTRANT
*cpp:
%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} %{municode:-DUNICODE} 
%{pthread:-D_REENTRANT} %{!no-pthread:-U_REENTRANT} 

$ x86_64-w64-mingw32-gcc-posix -dumpspecs | grep -B1 _REENTRANT 
*cpp:
%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} %{municode:-DUNICODE} 
%{!no-pthread:-D_REENTRANT} %{pthread:-U_REENTRANT} 

>  $ g++ -pthread -dM -E - < /dev/null | grep _REENTRANT
>  #define _REENTRANT 1
> 
>  $ x86_64-w64-mingw32-gcc -pthread -dM -E - < /dev/null | grep _REENTRANT
>  <crickets>

$ x86_64-w64-mingw32-gcc-posix -dM -E - < /dev/null | grep _REENTRANT 
#define _REENTRANT 1

> The "!no-pthread" part there, looks to me like either a typo or
> something that has outsmarted itself :)

It looks like some of the MinGW spec file stuff considers -pthread as a
toggle (but gets it wrong) and the rest considers it as an absolute specifier
(but using the switchable definitions so it's wrong half the time). So the
default works (no pthreads for Win32 threads, pthreads with POSIX threads
funnily enough) but trying to enable or disable things fails.

Anyway thanks for filing this, I'll take care of it in the next few weeks!

Regards,

Stephen

Attachment: pgptlNC02svT5.pgp
Description: OpenPGP digital signature

Reply via email to