Skip to content

ASpinlockMutex#

Synchronization primitive that is implemented with atomic values instead of doing syscalls.

Header:#include <AUI/Thread/AMutex.h>
CMake:aui_link(my_target PUBLIC aui::core)

Detailed Description#

In contrast to a regular mutex, threads will busy-wait (infinitely check for unlocked state) and waste CPU cycles instead of yielding the CPU to another thread with a syscall.

ASpinlockMutex may be faster than a regular mutex in some cases. Use benchmarks to compare.

Examples#

examples/7guis/flight_booker/src/main.cpp

7GUIs Flight Booker - Flight Booker.

constexpr auto REGEX_DATE = ctre::match<"([0-9]+)\\.([0-9]+)\\.([0-9]{4})">;

struct DateTextFieldState {
    AProperty<AOptional<system_clock::time_point>> parsed;
    ASpinlockMutex userChangesText;
};

auto formatDate(system_clock::time_point date) { return "{0:%d}.{0:%m}.{0:%G}"_format(date); }

AOptional<system_clock::time_point> parseDate(AStringView s) {

Public Methods#

try_lock#


bool ASpinlockMutex::try_lock()

Tries to acquire the mutex without blocking.

Returns
true if the mutex is successfully acquired, false otherwise.