
4 Features
The files mutex.mo and __mutex.mo in the utils directory implement mutual exclusion primitives. They work with the thread mechanism running in pre-emption mode.
There are five different demonstration programs in MLW/demo/threads:
dining_philosophers.sml sleeping_barber.sml bounded_buffer.sml cigarette_smokers.sml readers_writers.smlBrief documentation of the mutex interface follows.
Mutex Exception
newCountingMutex counter -> mutex
int. The mutex returned is of type mutex.
newBinaryMutex isClaimed -> mutex
bool. The mutex returned is of type mutex.
test mutex-list -> bool
true if all mutexes in mutex-list (type mutex list) are free at the time of the call, and false otherwise. It does not block.
testAndClaim mutex-list -> bool
test, but also claims the mutexes in mutex-list if they are all available, returning true. Returns false otherwise.
wait mutex-list -> ()
mutex list) are simultaneously free. Returns unit.
signal mutex-list -> ()
mutex list) are free, waking every thread waiting on the mutexes in the list. Returns unit.
query mutex -> thread-list
MLWorks.Threads.Internal.thread_id list.
allSleeping thread-list -> bool
true if every thread in thread-list is sleeping at the time of the call, and false otherwise. The thread-list must be of type MLWorks.Threads.Internal.thread_id list.
cleanUp () -> ()
unit and returns unit.
critical (mutex-list, f) a -> value
wait and a signal, with appropriate behavior on exceptions.
mutex list; f is a function (type 'a -> 'b) and a must be a valid argument to f.
await (mutex-list, c) -> ()
await function calls c to test for the condition.
() evaluates to true, await does not release the mutexes. The mutexes are only released if an exception occurs during the evaluation of c().
mutex list. The c function is of type unit -> bool. Returns unit.

Generated with Harlequin WebMaker