Thread creation and termination
val create : ('a -> 'b) -> 'a -> tThread.create funct argcreates a new thread of control, in which the function applicationfunct argis executed concurrently with the other threads of the program. The application ofThread.createreturns the handle of the newly created thread. The new thread terminates when the applicationfunct argreturns, either normally or by raising an uncaught exception. In the latter case, the exception is printed on standard error, but not propagated back to the parent thread. Similarly, the result of the applicationfunct argis discarded and not directly accessible to the parent thread.
val self : unit -> tReturn the thread currently executing.
val id : t -> intReturn the identifier of the given thread. A thread identifier is an integer that identifies uniquely the thread. It can be used to build data structures indexed by threads.
val kill : t -> unitTerminate prematurely the thread whose handle is given.
Suspending threads
val delay : float -> unitdelay dsuspends the execution of the calling thread fordseconds. The other program threads continue to run during this time.
val join : t -> unitjoin thsuspends the execution of the calling thread until the threadthhas terminated.
val wait_read : Unix.file_descr -> unitSee
Thread.wait_write.
val wait_write : Unix.file_descr -> unitThis function does nothing in this implementation.
val wait_timed_read : Unix.file_descr -> float -> bool
val wait_timed_write : Unix.file_descr -> float -> boolSuspend the execution of the calling thread until at least one character or EOF is available for reading (
wait_read) or one character can be written without blocking (wait_write) on the given Unix file descriptor. Wait for at most the amount of time given as second argument (in seconds). Returntrueif the file descriptor is ready for input/output andfalseif the timeout expired.These functions return immediately
truein the Win32 implementation.
val select : Unix.file_descr list -> Unix.file_descr list -> Unix.file_descr list -> float -> Unix.file_descr list * Unix.file_descr list * Unix.file_descr listSuspend the execution of the calling thread until input/output becomes possible on the given Unix file descriptors. The arguments and results have the same meaning as for
Unix.select. This function is not implemented yet under Win32.
val wait_pid : int -> int * Unix.process_statuswait_pid psuspends the execution of the calling thread until the process specified by the process identifierpterminates. Returns the pid of the child caught and its termination status, as perUnix.wait. This function is not implemented under MacOS.
val yield : unit -> unitRe-schedule the calling thread without suspending it. This function can be used to give scheduling hints, telling the scheduler that now is a good time to switch to other threads.
Management of signals
val sigmask : Unix.sigprocmask_command -> int list -> int listsigmask cmd sigschanges the set of blocked signals for the calling thread. IfcmdisSIG_SETMASK, blocked signals are set to those in the listsigs. IfcmdisSIG_BLOCK, the signals insigsare added to the set of blocked signals. IfcmdisSIG_UNBLOCK, the signals insigsare removed from the set of blocked signals.sigmaskreturns the set of previously blocked signals for the thread.
val wait_signal : int list -> intwait_signal sigssuspends the execution of the calling thread until the process receives one of the signals specified in the listsigs. It then returns the number of the signal received. Signal handlers attached to the signals insigswill not be invoked. The signalssigsare expected to be blocked before callingwait_signal.