Yes, glibc uses a stub implementation of various pthread functions, so single-threaded programs donβt need to spend cycles doing things like locking and unlocking mutexes, and yet they donβt need to reference another C library (for example, for example, in the Microsoft world).
For example, according to POSIX, every time you call fputc(ch, stream) , the mutex is locked and unlocked. If you do not want this, you call fputc_unlocked . But when you do this, you use the POSIX extension associated with stream processing; This is not a suitable solution for programs that do not use POSIX or do not use the streaming API.
Overriding stub pthread functions with real ones (in dynamic glibc) is not based on weak characters . The shared library mechanism allows you to override undefined definitions.
Weak characters are a mechanism that allows you to redefine a character with static binding.
If you need a source for the above statement, here it is:
"Note that a definition in a DSO that is weak has no effect. Weak definitions play a role in static communication." [Ulrich Drapper, "How to write shared libraries . "
If you run nm in static glibc on your system (if you have one), libc.a , you will notice that functions like pthread_mutex_lock are marked as weak. In the dynamic version of libc.so.<whatetever> functions are not marked as weak.
Note: you must use nm -D or nm --dynamic to view characters in a shared library. nm will not give anything in the shared library. If so, you are looking at debugging symbols, not dynamic symbols.
source share