Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need -D_REENTRANT with -pthreads?

On Linux (kernel 2.6.5) our build system calls gcc with -D_REENTRANT.

Is this still required when using pthreads?

How is it related to gcc -pthread option? I understand that I should use -pthread with pthreads, do I still need -D_REENTRANT?

On a side note, is there any difference that you know off between the usage of REENTRANT between gcc 3.3.3 and gcc 4.x.x ?

When I use -pthread gcc option I can see that _REENTRANT gets defined. Will omitting -D_REENTRANT from command line make any difference, for example could some objects be compiled without multithreaded support and then linked into binary that uses pthreads and will cause problems?

I assume it should be ok just to use: g++ -pthread

> echo | g++          -E -dM -c - > singlethreaded > echo | g++ -pthread -E -dM -c - > multithreaded > diff singlethreaded multithreaded 39a40 > #define _REENTRANT 1 

We're compiling multiple static libraries and applications that link with the static libraries, both libraries and application use pthreads.

I believe it was required at some stage in the past but want to know if it is still required. Googling hasn't returned any recent information mentioning -D_REENTRANT with pthreads. Could you point me to links or references discussing the use in recent version of kernel/gcc/pthread?

Clarification: At the moment we're using -D_REENTRANT and -lpthread, I assume I can replace them with just g++ -pthread, looking at man gcc it sets the flags for both preprocessor and linker. Any thoughts?

like image 943
stefanB Avatar asked May 18 '09 00:05

stefanB


People also ask

How long should you wait to dye your hair again with box dye?

Wait At Least 2 Weeks to Re-Dye Trichologists (hair scientists) recommend waiting at least 2 weeks – but technically 15 days – before you re-dye your hair if it's already damaged. This is especially true if you've used permanent hair color or a high-volume developer (30 or 40 volume).

What you should do first before applying hair color?

"A good thing to do the day before coloring is to use a clarifying shampoo to remove any product buildup, and to help even the hair's porosity so color takes evenly," says White. "You should follow that with a deep conditioner to replace any moisture that may be lost during coloring."

How soon can I recolor my hair if I don't like the color?

How long should you wait before re-coloring your hair? It's generally suggested to wait at least four weeks between coloring hair. That's the minimum interval if you care about your hair but it would actually be better to wait somewhere around six or seven weeks if you're really scared of doing any damage.

What is the best toner for yellow bleached hair?

Purple formulas help cancel unwanted yellow or brassy tones, as purple and yellow are opposite on the color wheel and neutralize each other. Blue formulas are best for orange undertones and brassiness, and perform that same function.


2 Answers

For me the best answer was the comment from pts if only he bothered to submit it as answer:

You investigated properly and answered your own question. Use g++ -pthread, it is equivalent to g++ -lpthread -D_REENTRANT. Using g++ -D_REENTRANT would be different, it may not set all the linker flags. – pts May 18 at 0:30

like image 100
stefanB Avatar answered Oct 12 '22 09:10

stefanB


From the gcc info pages:

`-pthread'      Adds support for multithreading with the "pthreads" library.  This      option sets flags for both the preprocessor and linker. 

So just the -pthread flag should be sufficient. I wouldn't recommend only passing it to some of your code, however.

As Chris suggested in the comments, using gcc -dumpspecs on Linux does indeed confirm that it sets preprocessor flags as well:

%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT} 
like image 32
bdonlan Avatar answered Oct 12 '22 11:10

bdonlan