creates a new thread of control to evaluate the body of f. A new unique ID for the thread is created and returned.

val yield : unit -> unit

This function can be used to implement an explicit context switch. Since CML is preemptively scheduled, it should never be necessary for user programs to call this function. It is mainly used for performance measurements.

exit ()

causes the calling thread to terminate.

getTid ()

returns the thread ID of the calling thread.

sameTid (tid1, tid2)

returns true, if the two thread IDs are the same ID.

compareTid (tid1, tid2)

compares the two thread IDs and returns their order in the total ordering of thread IDs. The precise semantics of this ordering is left unspecified, other than to say it is a total order.

hashTid tid

returns a hashing of the thread ID tid.

tidToString tid

returns a string representation of the thread ID tid.

joinEvt tid

creates an event value for synchronizing on the termination of the thread with the ID tid. There are three ways that a thread may terminate: the function that was passed to spawn (or spawnc) may return; it may call the exit function, or it may have an uncaught exception. Note that joinEvt does not distinguish between these cases; it also does not become enabled if the named thread deadlocks (even if it is garbage collected).

channel ()

creates a new synchronous channel.

sameChannel (ch1, ch2)

returns true, if the two channels are the same channel.

send (ch, msg)

sends the message msg on the synchronous channel ch. This operation blocks the calling thread until there is another thread attempting to receive a message from the channel ch, at which point the receiving thread gets the message and both threads continue execution.

recv ch

receives a message from the channel ch. This operation blocks the calling thread until there is another thread attempting to send a message on the channel ch, at which point both threads continue execution.

val sendEvt :'a chan *'a-> unit eventval recvEvt :'a chan ->'a event

These functions create event values to represent the send and recv operations.

sendPoll (ch, msg)

attempts to send the message msg on the synchronous channel ch. If this operation can complete without blocking the calling thread, then the message is sent and true is returned. Otherwise, no communication is preformed and false is returned. This function is not recommended for general use; it is provided as an efficiency aid for certain kinds of protocols.

recvPoll ch

attempts to receive a message from the channel ch. If there is no other thread offering to send a message on ch, then this returns NONE, otherwise it returns SOME wrapped around the message. This function is not recommended for general use; it is provided as an efficiency aid for certain kinds of protocols.

wrap (ev, f)

wraps the post-synchronization action f around the event value ev.

wrapHandler (ev, h)

wraps the exception handler function h around the event value ev. If, during execution of some post-synchronization action in ev, an exception is raised, it will be caught and passed to h. Nesting of handlers works as would be expected: the innermost handler is the first one invoked. Note that exceptions raised in the pre-synchronization actions in ev (i.e., actions defined by guard and withNack) are not handled by h.

guard g

creates a delayed event value from the function g. When the resulting event value is synchronized on, the function g will be evaluated and the resulting event value will be used in its place in the synchronization. This provides a mechanism for implementing pre-synchronization actions, such as sending a request to a server.

withNack g

creates a delayed event value from the function g. As in the case of guard, the function g will be evaluated at synchronization time and the resulting event value will be used in its place in the synchronization. Furthermore, when g is evaluated, it is passed a negative acknowledgement event as an argument. This negative acknowledgement event is enabled in the case where some other event involved in the synchronization is chosen instead of the one produced by g. The withNack combinator provides a mechanism for informing servers that a client has aborted a transaction.

choose evs

constructs an event value that represents the non-deterministic choice of the events in the list evs.

sync ev

synchronizes the calling thread on the event ev.

select evs

synchronizes on the non-deterministic choice of the events in the list evs. It is semantically equivalant to: