1Thread(3)                        OCaml library                       Thread(3)
2
3
4

NAME

6       Thread - Lightweight threads for Posix 1003.1c and Win32.
7

Module

9       Module   Thread
10

Documentation

12       Module Thread
13        : sig end
14
15
16       Lightweight threads for Posix 1003.1c and Win32.
17
18
19
20
21
22       type t
23
24
25       The type of thread handles.
26
27
28
29
30   Thread creation and termination
31       val create : ('a -> 'b) -> 'a -> t
32
33
34       Thread.create  funct  arg creates a new thread of control, in which the
35       function application funct arg is executed concurrently with the  other
36       threads  of  the program.  The application of Thread.create returns the
37       handle of the newly created thread.  The new thread terminates when the
38       application  funct  arg  returns,  either normally or by raising an un‐
39       caught exception.  In the latter case,  the  exception  is  printed  on
40       standard  error,  but  not  propagated back to the parent thread. Simi‐
41       larly, the result of the application funct arg is discarded and not di‐
42       rectly accessible to the parent thread.
43
44
45
46       val self : unit -> t
47
48       Return the handle for the thread currently executing.
49
50
51
52       val id : t -> int
53
54       Return  the  identifier  of the given thread. A thread identifier is an
55       integer that identifies uniquely the thread.  It can be used  to  build
56       data structures indexed by threads.
57
58
59
60       val exit : unit -> unit
61
62       Terminate prematurely the currently executing thread.
63
64
65
66       val kill : t -> unit
67
68       This  function  was  supposed to terminate prematurely the thread whose
69       handle is given.  It is not currently implemented due to problems  with
70       cleanup  handlers  on  many  POSIX  1003.1c implementations.  It always
71       raises the Invalid_argument exception.
72
73
74
75
76   Suspending threads
77       val delay : float -> unit
78
79
80       delay d suspends the execution of the calling thread for d seconds. The
81       other program threads continue to run during this time.
82
83
84
85       val join : t -> unit
86
87
88       join  th  suspends the execution of the calling thread until the thread
89       th has terminated.
90
91
92
93       val yield : unit -> unit
94
95       Re-schedule the calling thread without suspending  it.   This  function
96       can be used to give scheduling hints, telling the scheduler that now is
97       a good time to switch to other threads.
98
99
100
101
102   Waiting for file descriptors or processes
103       The functions below are leftovers from an earlier,  VM-based  threading
104       system.   The  Unix module provides equivalent functionality, in a more
105       general and more standard-conformant manner.  It is recommended to  use
106       Unix functions directly.
107
108       val wait_read : Unix.file_descr -> unit
109
110       This function does nothing in the current implementation of the thread‐
111       ing library and can be removed from all user programs.
112
113
114
115       val wait_write : Unix.file_descr -> unit
116
117       This function does nothing in the current implementation of the thread‐
118       ing library and can be removed from all user programs.
119
120
121
122       val wait_timed_read : Unix.file_descr -> float -> bool
123
124       See Thread.wait_timed_write .
125
126
127
128       val wait_timed_write : Unix.file_descr -> float -> bool
129
130       Suspend  the execution of the calling thread until at least one charac‐
131       ter or EOF is available for reading ( wait_timed_read ) or one  charac‐
132       ter  can  be written without blocking ( wait_timed_write ) on the given
133       Unix file descriptor. Wait for at most the amount of time given as sec‐
134       ond argument (in seconds).  Return true if the file descriptor is ready
135       for input/output and false if the timeout expired.  The same  function‐
136       ality can be achieved with Unix.select .
137
138
139
140       val   select   :   Unix.file_descr  list  ->  Unix.file_descr  list  ->
141       Unix.file_descr list -> float -> Unix.file_descr list * Unix.file_descr
142       list * Unix.file_descr list
143
144       Same  function  as  Unix.select .  Suspend the execution of the calling
145       thread until input/output becomes possible on the given Unix  file  de‐
146       scriptors.   The  arguments  and  results  have the same meaning as for
147       Unix.select .
148
149
150
151       val wait_pid : int -> int * Unix.process_status
152
153       Same function as Unix.waitpid .  wait_pid p suspends the  execution  of
154       the  calling  thread until the process specified by the process identi‐
155       fier p terminates. Returns the pid of the child caught and its termina‐
156       tion status, as per Unix.wait .
157
158
159
160
161   Management of signals
162       Signal  handling follows the POSIX thread model: signals generated by a
163       thread are delivered to that thread; signals generated  externally  are
164       delivered  to  one  of the threads that does not block it.  Each thread
165       possesses a set  of  blocked  signals,  which  can  be  modified  using
166       Thread.sigmask  .   This  set  is  inherited  at  thread creation time.
167       Per-thread signal masks are supported only by the system thread library
168       under Unix, but not under Win32, nor by the VM thread library.
169
170       val sigmask : Unix.sigprocmask_command -> int list -> int list
171
172
173       sigmask  cmd  sigs  changes  the set of blocked signals for the calling
174       thread.  If cmd is SIG_SETMASK , blocked signals are set  to  those  in
175       the list sigs .  If cmd is SIG_BLOCK , the signals in sigs are added to
176       the set of blocked signals.  If cmd is SIG_UNBLOCK  ,  the  signals  in
177       sigs  are removed from the set of blocked signals.  sigmask returns the
178       set of previously blocked signals for the thread.
179
180
181
182       val wait_signal : int list -> int
183
184
185       wait_signal sigs suspends the execution of the calling thread until the
186       process  receives  one  of the signals specified in the list sigs .  It
187       then returns the number of the signal received.   Signal  handlers  at‐
188       tached  to  the  signals in sigs will not be invoked.  The signals sigs
189       are expected to be blocked before calling wait_signal .
190
191
192
193
194
195OCamldoc                          2021-07-22                         Thread(3)
Impressum