Final Platform Layer 0.9.8-beta
|
This section explains how to create and handling of Mutexes.
A mutex is a Kernel-Level object used to prevent race conditions when multiple Threads access the same code section.
With a Mutex, you can ensure that only one thread at a time can access a code section.
Call fplMutexInit() with a pointer to fplMutexHandle argument, to initialize a Mutex.
After the initialization is done, you can start locking and unlocking it.
When you are done with the Mutex call fplMutexDestroy() to release its internal resources.
Call fplMutexLock() with a pointer to fplMutexHandle as an argument, to lock a Mutex.
It this Mutex is already locked, the current thread will wait forever until it gets unlocked by the owner Thread.
If this Mutex is not locked yet, it will be locked by the calling Thread.
Call fplMutexUnlock() with a pointer to fplMutexHandle as an argument, to unlock a Mutex.
The Mutex will be unlocked only when this function is called from the owner Thread.
If this Mutex was not locked or the owner Thread does not match it will fail.
Call fplMutexTryLock() with a pointer to fplMutexHandle as an argument, to try to lock a Mutex.
If the Mutex is already locked, the current thread will not be blocked and the function returns false.
If this Mutex is not locked yet, it will be locked by the calling Thread.