StuBS
Ticketlock Class Reference

By the use of Ticketlocks, it is possible to serialize blocks of code that might run parallel on multiple CPU cores. More...

#include <sync/ticketlock.h>

Public Member Functions

 Ticketlock ()
 Constructor.
void lock ()
 Enters the critical area. In case the area is already locked, lock() will actively wait for the area can be entered.
void unlock ()
 Unblocks the critical area.

Private Member Functions

 Ticketlock (const Ticketlock &copy)=delete
Ticketlock & operator= (const Ticketlock &)=delete

Private Attributes

cache_aligned size_t serving
cache_aligned size_t ticket

Detailed Description

By the use of Ticketlocks, it is possible to serialize blocks of code that might run parallel on multiple CPU cores.

Synchronization is implemented using a lock and a ticket variable. Once a thread tries to enter the critical area, it obtains a ticket by atomic increment of the ticket variable and waits until the lock variable is equal to its ticket. When a thread leaves the critical area, it increments the lock variable by one and thereby allows the next thread to enter the critical area.

Note
If you want that things just work, choose __ATOMIC_SEQ_CST as memorder. This is not the most efficient memory order but works reasonably well.

Atomic Builtins in GCC manual

Constructor & Destructor Documentation

◆ Ticketlock() [1/2]

Ticketlock::Ticketlock ( const Ticketlock & copy)
privatedelete

◆ Ticketlock() [2/2]

Ticketlock::Ticketlock ( )
inline

Constructor.

Todo
Complete Constructor (for MPStuBS)

Member Function Documentation

◆ operator=()

Ticketlock & Ticketlock::operator= ( const Ticketlock & )
privatedelete

◆ lock()

void Ticketlock::lock ( )
inline

Enters the critical area. In case the area is already locked, lock() will actively wait for the area can be entered.

See also
Core::pause()
Todo
Implement Method (for MPStuBS)

◆ unlock()

void Ticketlock::unlock ( )
inline

Unblocks the critical area.

Todo
Implement Method (for MPStuBS)

Member Data Documentation

◆ serving

cache_aligned size_t Ticketlock::serving
private

◆ ticket

cache_aligned size_t Ticketlock::ticket
private

The documentation for this class was generated from the following file: