1Domain(3) OCaml library Domain(3)
2
3
4
6 Domain - no description
7
9 Module Domain
10
12 Module Domain
13 : sig end
14
15
16 Alert unstable. The Domain interface may change in incompatible ways
17 in the future.
18
19
20
21
22
23
24
25 Domains.
26
27 See 'Parallel programming' chapter in the manual.
28
29 type 'a t
30
31
32 A domain of type 'a t runs independently, eventually producing a result
33 of type 'a, or an exception
34
35
36
37 val spawn : (unit -> 'a) -> 'a t
38
39
40 spawn f creates a new domain that runs in parallel with the current do‐
41 main.
42
43
44
45 val join : 'a t -> 'a
46
47
48 join d blocks until domain d runs to completion. If d results in a
49 value, then that is returned by join d . If d raises an uncaught excep‐
50 tion, then that is re-raised by join d .
51
52
53 type id = private int
54
55
56 Domains have unique integer identifiers
57
58
59
60 val get_id : 'a t -> id
61
62
63 get_id d returns the identifier of the domain d
64
65
66
67
68 val self : unit -> id
69
70
71 self () is the identifier of the currently running domain
72
73
74
75 val before_first_spawn : (unit -> unit) -> unit
76
77
78 before_first_spawn f registers f to be called before the first domain
79 is spawned by the program. The functions registered with be‐
80 fore_first_spawn are called on the main (initial) domain. The functions
81 registered with before_first_spawn are called in 'first in, first out'
82 order: the oldest function added with before_first_spawn is called
83 first.
84
85
86 Raises Invalid_argument if the program has already spawned a domain.
87
88
89
90 val at_exit : (unit -> unit) -> unit
91
92
93 at_exit f registers f to be called when the current domain exits. Note
94 that at_exit callbacks are domain-local and only apply to the calling
95 domain. The registered functions are called in 'last in, first out' or‐
96 der: the function most recently added with at_exit is called first. An
97 example:
98
99
100 let temp_file_key = Domain.DLS.new_key (fun _ ->
101 let tmp = snd (Filename.open_temp_file "" "") in
102 Domain.at_exit (fun () -> close_out_noerr tmp);
103 tmp)
104
105
106 The snippet above creates a key that when retrieved for the first time
107 will open a temporary file and register an at_exit callback to close
108 it, thus guaranteeing the descriptor is not leaked in case the current
109 domain exits.
110
111
112
113 val cpu_relax : unit -> unit
114
115 If busy-waiting, calling cpu_relax () between iterations will improve
116 performance on some CPU architectures
117
118
119
120 val is_main_domain : unit -> bool
121
122
123 is_main_domain () returns true if called from the initial domain.
124
125
126
127 val recommended_domain_count : unit -> int
128
129 The recommended maximum number of domains which should be running si‐
130 multaneously (including domains already running).
131
132 The value returned is at least 1 .
133
134
135 module DLS : sig end
136
137
138
139
140
141
142
143OCamldoc 2023-07-20 Domain(3)