1Thread(3) OCaml library Thread(3)
2
3
4
6 Thread - Lightweight threads.
7
9 Module Thread
10
12 Module Thread
13 : sig end
14
15
16 Lightweight threads.
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
32
33 val create : ('a -> 'b) -> 'a -> t
34
35
36 Thread.create funct arg creates a new thread of control, in which the
37 function application funct arg is executed concurrently with the other
38 threads of the program. The application of Thread.create returns the
39 handle of the newly created thread. The new thread terminates when the
40 application funct arg returns, either normally or by raising an
41 uncaught exception. In the latter case, the exception is printed on
42 standard error, but not propagated back to the parent thread. Simi‐
43 larly, the result of the application funct arg is discarded and not
44 directly accessible to the parent thread.
45
46
47
48 val self : unit -> t
49
50 Return the thread currently executing.
51
52
53
54 val id : t -> int
55
56 Return the identifier of the given thread. A thread identifier is an
57 integer that identifies uniquely the thread. It can be used to build
58 data structures indexed by threads.
59
60
61
62 val exit : unit -> unit
63
64 Terminate prematurely the currently executing thread.
65
66
67
68 val kill : t -> unit
69
70 Terminate prematurely the thread whose handle is given. This function‐
71 ality is available only with bytecode-level threads.
72
73
74
75
76 === Suspending threads ===
77
78
79 val delay : float -> unit
80
81
82 delay d suspends the execution of the calling thread for d seconds. The
83 other program threads continue to run during this time.
84
85
86
87 val join : t -> unit
88
89
90 join th suspends the execution of the calling thread until the thread
91 th has terminated.
92
93
94
95 val wait_read : Unix.file_descr -> unit
96
97 See Thread.wait_write .
98
99
100
101 val wait_write : Unix.file_descr -> unit
102
103 Suspend the execution of the calling thread until at least one charac‐
104 ter or EOF is available for reading ( Thread.wait_read ) or one charac‐
105 ter can be written without blocking ( wait_write ) on the given Unix
106 file descriptor.
107
108
109
110 val wait_timed_read : Unix.file_descr -> float -> bool
111
112 See Thread.wait_timed_write .
113
114
115
116 val wait_timed_write : Unix.file_descr -> float -> bool
117
118 Same as Thread.wait_read and Thread.wait_write , but wait for at most
119 the amount of time given as second argument (in seconds). Return true
120 if the file descriptor is ready for input/output and false if the time‐
121 out expired.
122
123
124
125 val select : Unix.file_descr list -> Unix.file_descr list ->
126 Unix.file_descr list -> float -> Unix.file_descr list * Unix.file_descr
127 list * Unix.file_descr list
128
129 Suspend the execution of the calling thread until input/output becomes
130 possible on the given Unix file descriptors. The arguments and results
131 have the same meaning as for Unix.select .
132
133
134
135 val wait_pid : int -> int * Unix.process_status
136
137
138 wait_pid p suspends the execution of the calling thread until the Unix
139 process specified by the process identifier p terminates. A pid p of -1
140 means wait for any child. A pid of 0 means wait for any child in the
141 same process group as the current process. Negative pid arguments rep‐
142 resent process groups. Returns the pid of the child caught and its ter‐
143 mination status, as per Unix.wait .
144
145
146
147 val wait_signal : int list -> int
148
149
150 wait_signal sigs suspends the execution of the calling thread until the
151 process receives one of the signals specified in the list sigs . It
152 then returns the number of the signal received. Signal handlers
153 attached to the signals in sigs will not be invoked. Do not call
154 wait_signal concurrently from several threads on the same signals.
155
156
157
158 val yield : unit -> unit
159
160 Re-schedule the calling thread without suspending it. This function
161 can be used to give scheduling hints, telling the scheduler that now is
162 a good time to switch to other threads.
163
164
165
166
167
168OCamldoc 2018-07-14 Thread(3)