Jump to content

Programming Reference:OSMutex Class: Difference between revisions

From BCI2000 Wiki
Mellinger (talk | contribs)
No edit summary
 
Mellinger (talk | contribs)
Replaced content with "<tt>OSMutex</tt> is obsolete. Use <tt>std::mutex</tt> instead. ==See also== Programming Reference:OSThread Class, Programming Reference:OSEvent Class Category:..."
Tag: Replaced
Line 1: Line 1:
==Location==
<tt>OSMutex</tt> is obsolete. Use <tt>std::mutex</tt> instead.
<tt>BCI2000/src/shared/utils</tt>
 
==Synopsis==
The <tt>OSMutex</tt> class provides a wrapper for OS-dependent synchronization functionality, corresponding to a Windows or POSIX threads mutex object.
 
==Methods==
===OSMutex()===
Mutexes are created in released state, i.e. no thread owns the newly created mutex.
===~OSMutex()===
Releases all resources allocated for the mutex object.
===bool Acquire()===
Acquires ownership of the mutex for the current thread. When the mutex is owned by a different thread, the current thread is blocked until the owning thread calls <tt>Release()</tt> on the mutex object. When the mutex is already owned by the thread calling <tt>Acquire()</tt>, it does not block; rather, a lock count is increased, and the calling thread continues running. For each call to <tt>Acquire()</tt>, there must be a balancing call to <tt>Release()</tt> in order to make the mutex available to other threads. <tt>Acquire</tt> returns true when successful, and false otherwise.
===bool Release()===
Gives up ownership of the mutex for the current thread, or decreases the lock count when the mutex has been acquired multiple times by a thread. When multiple threads are waiting for the mutex, a random thread is unblocked. Returns true when successful, and false when an error occurred.
 
==Sub-classes==
===OSMutex::Lock(OSMutex)===
An object that acquires the specified mutex when created, and releases it when destructed.
===OSMutex::Unlock(OSMutex)===
An object that releases the specified mutex when created, and acquires it when destructed.
 
Use objects of type <tt>OSMutex::Lock</tt> and <tt>OSMutex::Unlock</tt> to make sure the mutex is restored to its previous state when the current scope is left. This is especially useful when it is possible that an exception is thrown while the mutex is in its altered state. During stack unwinding, the lock/unlock object's destructor is called, and the mutex is restored to its previous state, even when an exception is thrown.


==See also==
==See also==

Revision as of 16:17, 8 June 2022

OSMutex is obsolete. Use std::mutex instead.

See also

Programming Reference:OSThread Class, Programming Reference:OSEvent Class