Mutex: Difference between revisions

Added Prolog
(Added Prolog)
Line 828:
'[http://software-lab.de/doc/refR.html#release release]' function pair
can be used.
 
=={{header|Prolog}}==
SWI-Prolog implements mutexes, but other Prolog versions vary, so I'll use the SWI-Prolog implementation here.
 
To create a global mutex:
<lang prolog>mutex_create(Mutex, [alias(my_mutex)]).</lang>
The recommended way to use the mutex is by wrapping code in a with_mutex/2 call, eg:
<lang Prolog>synchronized_goal(G) :- with_mutex(my_mutex, call(G)).</lang>
This will wrap some code in a mutex to ensure exclusive access and release the mutex on completion (regardless or the result).
 
There are more options to lock, try_lock, unlock etc here, if needed: https://www.swi-prolog.org/pldoc/man?section=threadsync
 
=={{header|PureBasic}}==
Anonymous user