This is the mail archive of the libc-help@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: pthread_mutex_unlock takes 15x longer than pthread_mutex_lock


On 02/10/17 08:07, Ralph Loader wrote:
The time that an atomic operation takes on x86 is highly variable. I
believe that this is because pending data in processor write buffers are
flushed into the memory hierarchy by the atomic operation.

I am no expert, but I also think this to be so.

One possible mitigation is to use a pthread spinlock instead of a pthread
mutex; the former is released (on x86) by a normal write, not an atomic op.
This will make the unlock faster (but possibly take longer for the unlock
to be observed by other threads).

I may be wrong, but as I understand it, strictly speaking there are no *guarantees* this write will *ever* reach the memory hierarchy. In practise of course store buffers aren't much delayed, and it would be remarkable for one to be hung up forever - but I know of no *guarantee* that store buffers are actually pushed out to the memory hierarchy.


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