This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Dummy pthread functions in libc considered harmful


Andreas Schwab, le Tue 25 Aug 2015 09:09:58 +0200, a écrit :
> Samuel Thibault <samuel.thibault@ens-lyon.org> writes:
> > It's usually not programs which call pthread_mutex, but libraries which
> > want to be thread-safe without actually bringing the libpthread
> > dependencye.
> 
> Does the reason for avoiding the dependency still exist?  Surely the
> overhead of libpthread has been greatly reduced since the days of
> linuxthreads.

The overhead of pthread_mutex_lock in the uncontended case has not
really changed. E.g. in glibc 2.2 in 2002 it was already a mere compare
and swap instruction after just checking the time of lock.

A quick dumb measurement of for() { mutex_lock(); mutex_unlock(); } on
my laptop gives a 4x-5x factor between the empty hook without -lpthread
and a non-contended actual mutex_lock call with -lpthread.

Samuel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]