1Thread(3) OCaml library Thread(3)
2
3
4
6 Thread - Lightweight threads for Posix 1003.1c and Win32.
7
9 Module Thread
10
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
39 uncaught 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
42 directly accessible to the parent thread.
43
44
45
46 val self : unit -> t
47
48 Return 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 Terminate prematurely the thread whose handle is given.
69
70
71
72
73 Suspending threads
74 val delay : float -> unit
75
76
77 delay d suspends the execution of the calling thread for d seconds. The
78 other program threads continue to run during this time.
79
80
81
82 val join : t -> unit
83
84
85 join th suspends the execution of the calling thread until the thread
86 th has terminated.
87
88
89
90 val wait_read : Unix.file_descr -> unit
91
92 See Thread.wait_write .
93
94
95
96 val wait_write : Unix.file_descr -> unit
97
98 This function does nothing in this implementation.
99
100
101
102 val wait_timed_read : Unix.file_descr -> float -> bool
103
104 See Thread.wait_timed_write .
105
106
107
108 val wait_timed_write : Unix.file_descr -> float -> bool
109
110 Suspend the execution of the calling thread until at least one charac‐
111 ter or EOF is available for reading ( wait_read ) or one character can
112 be written without blocking ( wait_write ) on the given Unix file
113 descriptor. Wait for at most the amount of time given as second argu‐
114 ment (in seconds). Return true if the file descriptor is ready for
115 input/output and false if the timeout expired.
116
117 These functions return immediately true in the Win32 implementation.
118
119
120
121 val select : Unix.file_descr list -> Unix.file_descr list ->
122 Unix.file_descr list -> float -> Unix.file_descr list * Unix.file_descr
123 list * Unix.file_descr list
124
125 Suspend the execution of the calling thread until input/output becomes
126 possible on the given Unix file descriptors. The arguments and results
127 have the same meaning as for Unix.select . This function is not imple‐
128 mented yet under Win32.
129
130
131
132 val wait_pid : int -> int * Unix.process_status
133
134
135 wait_pid p suspends the execution of the calling thread until the
136 process specified by the process identifier p terminates. Returns the
137 pid of the child caught and its termination status, as per Unix.wait .
138 This function is not implemented under MacOS.
139
140
141
142 val yield : unit -> unit
143
144 Re-schedule the calling thread without suspending it. This function
145 can be used to give scheduling hints, telling the scheduler that now is
146 a good time to switch to other threads.
147
148
149
150
151 Management of signals
152 Signal handling follows the POSIX thread model: signals generated by a
153 thread are delivered to that thread; signals generated externally are
154 delivered to one of the threads that does not block it. Each thread
155 possesses a set of blocked signals, which can be modified using
156 Thread.sigmask . This set is inherited at thread creation time.
157 Per-thread signal masks are supported only by the system thread library
158 under Unix, but not under Win32, nor by the VM thread library.
159
160 val sigmask : Unix.sigprocmask_command -> int list -> int list
161
162
163 sigmask cmd sigs changes the set of blocked signals for the calling
164 thread. If cmd is SIG_SETMASK , blocked signals are set to those in
165 the list sigs . If cmd is SIG_BLOCK , the signals in sigs are added to
166 the set of blocked signals. If cmd is SIG_UNBLOCK , the signals in
167 sigs are removed from the set of blocked signals. sigmask returns the
168 set of previously blocked signals for the thread.
169
170
171
172 val wait_signal : int list -> int
173
174
175 wait_signal sigs suspends the execution of the calling thread until the
176 process receives one of the signals specified in the list sigs . It
177 then returns the number of the signal received. Signal handlers
178 attached to the signals in sigs will not be invoked. The signals sigs
179 are expected to be blocked before calling wait_signal .
180
181
182
183
184
185OCamldoc 2019-07-30 Thread(3)