MySQL 8.4.3
Source Code Documentation
lock Namespace Reference

Provides atomic access in shared-exclusive modes. More...

Classes

class  Shared_spin_lock
 

Detailed Description

Provides atomic access in shared-exclusive modes.

Shared mode allows for several threads to share lock acquisition. Exclusive mode will allow for a single thread to acquire the lock.

The implementation also provides re-entrance, meaning that a thread is allowed to acquire the lock in the same mode several times without blocking. Re-entrance is symmetric, meaning, in the case the lock is acquired several times by the same thread, it should be released the same amount of times.

Acquisition request priority management is implemented to avoid starvation, meaning:

1) When no thread is holding the lock, acquisition is granted to the first thread to request it.

2) If the lock is being held in shared mode and an exclusive acquisition request is made, no more shared or exclusive acquisition requests are granted until the exclusivity request is granted and released.

The acquisition relation given to concurrent requests is as follows:


| S2 | E2 | +--------------------------—+--------------------------—+ | REQUEST | ACQUIRED | REQUEST | ACQUIRED | --------------—+-----------—+-----------------------------------------—+ | | REQUEST | S1 & S2 | S1 & S2 | S1 | E2 | E2 | | S1 |------—+-----------—+-----------—+-----------—+-----------—+ | | ACQUIRED| S1 & S2 | S1 & S2 | S1 | - | ----—+------—+-----------—+-----------—+-----------—+-----------—+ | | REQUEST | E1 | S2 | E1 | E2 | E2 | | E1 |------—+-----------—+-----------—+-----------—+-----------—+

| | ACQUIRED| E1 | - | E1 | - |

Legend:

  • S1: Thread that is requesting or has acquired in shared mode
  • S2: Thread that is requesting or has acquired in shared mode
  • E1: Thread that is requesting or has acquired in exclusive mode
  • E2: Thread that is requesting or has acquired in exclusive mode