This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Dummy pthread functions in libc considered harmful
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Torvald Riegel <triegel at redhat dot com>
- Cc: Samuel Thibault <samuel dot thibault at ens-lyon dot org>, Andreas Schwab <schwab at suse dot de>, Rich Felker <dalias at libc dot org>, libc-alpha at sourceware dot org
- Date: Thu, 27 Aug 2015 08:36:12 +0200
- Subject: Re: Dummy pthread functions in libc considered harmful
- Authentication-results: sourceware.org; auth=none
- References: <mvmr3ms4sbj dot fsf at hawking dot suse dot de> <20150824153816 dot GC3210 at type dot bordeaux dot inria dot fr> <20150824162250 dot GD32742 at brightrain dot aerifal dot cx> <20150824162641 dot GH3210 at type dot bordeaux dot inria dot fr> <mvmbndv4zeh dot fsf at hawking dot suse dot de> <20150825114104 dot GF3162 at type dot bordeaux dot inria dot fr> <1440503110 dot 27492 dot 146 dot camel at localhost dot localdomain>
On Tue, Aug 25, 2015 at 01:45:10PM +0200, Torvald Riegel wrote:
> On Tue, 2015-08-25 at 13:41 +0200, Samuel Thibault wrote:
> > 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.
>
> It has on archs such as x86 simply because the overhead of atomic HW
> instructions has been reduced significantly.
>
Still code of that stays same.
I wonder if new processor internally use transactional memory for lock
operations to reduce that.
> > 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.
>
> You should do at least something in the critical section to create a
> somewhat realistic benchmark.
Do you have one?