This is the mail archive of the 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]

[PATCH] Correct mutex type check for disable lock elision via pthread_mutexattr_settype call


if glibc is build with --enable-lock-elision=yes,
all default mutexes are elided (only for supported architectures).
Someone can disable the elision for one specific mutex with
a call to pthread_mutexattr_settype.
Currently you can specify either PTHREAD_MUTEX_NORMAL or PTHREAD_MUTEX_DEFAULT, because they are both defined to 0.
The function checks for type PTHREAD_MUTEX_DEFAULT
and then disables elision.

For correctness, the function should check against PTHREAD_MUTEX_NORMAL!
According to POSIX, PTHREAD_MUTEX_NORMAL shall deadlock if a thread tries to relock a mutex without first unlocking it.
In case of PTHREAD_MUTEX_DEFAULT, the behavior is undefined.
Thus the mutex can be elided with PTHREAD_MUTEX_DEFAULT, but not with PTHREAD_MUTEX_NORMAL.
The same can be read in the lock elision implementation guidelines


2014-04-01  Stefan Liebler  <>

	* nptl/pthread_mutexattr_settype.c
	Disable lock elision for PTHREAD_MUTEX_NORMAL.

Attachment: patchGlibcDisableElision
Description: Text document

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