Mutex Flavors

Connoisseurs of mutexes distinguish various attributes of mutexes. It helps to know some of these, because they involve tradeoffs of generality and efficiency. Picking the right one often helps performance. Mutexes can be described by the following qualities, also summarized in the table below.

The following is a summary of mutex behaviors:

Traits and Behaviors of Mutexes

Mutex

Scalable

Fair

Recursive

Long Wait

Size

mutex

OS dependent

OS dependent

no

blocks

≥ 3 words

recursive_mutex

OS dependent

OS dependent

yes

blocks

≥ 3 words

spin_mutex

no

no

no

yields

1 byte

queuing_mutex

no

yields

1 word

spin_rw_mutex

no

no

no

yields

1 word

queuing_rw_mutex

no

yields

1 word

null_mutex[6]

moot

never

empty

null_rw_mutex

moot

never

empty

[5] The yielding is implemented via SwitchToThread() on Microsoft Windows* operating systems and by sched_yield() on other systems.

[6] Null mutexes are considered fair by Intel® TBB because they cannot cause starvation. They lack any non-static data members.