Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pthread_mutex_lock / unlock affecting compiler optimization and/or caching ??

3 views
Skip to first unread message

mynickmynick

unread,
Jul 17, 2008, 9:55:29 AM7/17/08
to
How could pthread_mutex_lock / unlock affect compiler optimization and/
or caching ??
in particular how could it increase cache ping-pong / false sharing??

thank you

Chris Thomasson

unread,
Jul 17, 2008, 2:39:19 PM7/17/08
to
"mynickmynick" <mynick...@yahoo.com> wrote in message
news:6fc6af0c-112c-442d...@w7g2000hsa.googlegroups.com...

> How could pthread_mutex_lock / unlock affect compiler optimization and/
> or caching ??

First, read this:

http://groups.google.com/group/comp.programming.threads/browse_frm/thread/63f6360d939612b3

The compiler must not move anything outside of the critical-section! Ouch.


> in particular how could it increase cache ping-pong

I guess certain lock implementations can increase cache coherency traffic
within the lock procedure itself. Think of spinlocks or adaptive mutexs
which lack appropriate backoff mechanisms.


> false sharing??

They can definitely increase false sharing if the lock state is not properly
padded to and aligned on L2 cache line boundaries; example:

http://groups.google.com/group/comp.programming.threads/msg/88bd832858072802

http://groups.google.com/group/comp.programming.threads/msg/9701b98be6ed6e7f
(run the program contained within that thread to see for yourself...)

mynickmynick

unread,
Jul 18, 2008, 4:18:36 AM7/18/08
to

> > false sharing??
>
> They can definitely increase false sharing if the lock state is not properly
> padded to and aligned on L2 cache line boundaries; example:
>
> http://groups.google.com/group/comp.programming.threads/msg/88bd83285...
>
> http://groups.google.com/group/comp.programming.threads/msg/9701b98be...

> (run the program contained within that thread to see for yourself...)

but this not on linux with pthread_mutex_lock, right?

Chris Thomasson

unread,
Jul 19, 2008, 5:47:20 AM7/19/08
to
"mynickmynick" <mynick...@yahoo.com> wrote in message
news:11c71795-b29d-4ba0...@q28g2000prh.googlegroups.com...

It certainly could be! If the `pthread_mutex_t' data-structures are not
properly
padded and aligned, well...

:^o

0 new messages