Any advantage when calling gcc _without_ -pthread?

We know that adding -pthread makes GCC use fallback / thread safe code (when compiling C / C ++ code). Although I assume that this is true, you could save a couple of cycles here and there, if you allow without re-registering - I wonder if there is any actual advantage to not always indicate -pthread. There is?

+4
source share
2 answers

One example: the libstdC ++ implementation does std::shared_ptr not use locking when compiling without-pthread , which can give you a good performance boost if you're using shared pointers in a single-threaded environment.

+4
source

In C ++, the philosophy of the language has always been "you do not pay for what you do not need." If your program works with a single thread and does not require repeated functions, there is no real incentive to add -pthread.

The cost of using a reentrant function will always be higher or equal to the non-tolerant version of the function. Either on time (you need to lock the mutexes to protect variables), or allocate memory to call each function, and not use a static buffer.

, pthreads (pthreads - POSIX).

0

All Articles