Skip to content

Commit aa2a346

Browse files
remove Async_switch, fix documentation regarding async_method
1 parent 2bb5c46 commit aa2a346

File tree

3 files changed

+35
-64
lines changed

3 files changed

+35
-64
lines changed

src/unix/lwt_process.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66
(** Process management *)
77

8-
(** This module allows you to spawn processes and communicate with them. *)
8+
(** This module allows you to spawn processes and communicate with them.
9+
10+
This module makes heavy use of {!Lwt_unix.fork}. Important caveats are
11+
documented there. Read them. TL;DR: no domains, no threads, no preemptive,
12+
yes [Async_none]. *)
913

1014
type command = string * string array
1115
(** A command. The first field is the name of the executable and

src/unix/lwt_unix.cppo.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ open Lwt.Infix
1919
type async_method =
2020
| Async_none
2121
| Async_detach
22-
| Async_switch
2322

2423
let default_async_method_var = Atomic.make Async_detach
2524

@@ -30,11 +29,9 @@ let () =
3029
Atomic.set default_async_method_var Async_none
3130
| "detach" ->
3231
Atomic.set default_async_method_var Async_detach
33-
| "switch" ->
34-
Atomic.set default_async_method_var Async_switch
3532
| str ->
3633
Printf.eprintf
37-
"%s: invalid lwt async method: '%s', must be 'none', 'detach' or 'switch'\n%!"
34+
"%s: invalid lwt async method: '%s', must be 'none' or 'detach'\n%!"
3835
(Filename.basename Sys.executable_name) str
3936
with Not_found ->
4037
()
@@ -55,9 +52,6 @@ let with_async_none f =
5552
let with_async_detach f =
5653
Lwt.with_value async_method_key (Some Async_detach) f
5754

58-
let with_async_switch f =
59-
Lwt.with_value async_method_key (Some Async_switch) f
60-
6155
(* +-----------------------------------------------------------------+
6256
| Notifications management |
6357
+-----------------------------------------------------------------+ *)

src/unix/lwt_unix.cppo.mli

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,16 @@ val fork : unit -> int
211211
- None of the above is necessary if you intend to call [exec]. Indeed, in
212212
that case, it is not even necessary to use [Lwt_unix.fork]. You can use
213213
{!Unix.fork}.
214-
- To abandon some more promises, see {!Lwt.abandon_paused}. *)
214+
- To abandon some more promises, see {!Lwt.abandon_paused}.
215+
216+
Furthermore:
217+
218+
- Calling [Lwt_unix.fork] raises an execption if [Domain.spawn] has been
219+
called at any point in the program's past.
220+
- Calling [Lwt_unix.fork] can result in the child process being in a
221+
corrupted state if any thread has been started. Lwt starts threads when
222+
[Lwt_preemptive.detach] is called. Lwt implicitly starts threads to
223+
perform blocking I/O unless the {!async_method} is set to [Async_none]. *)
215224

216225
type process_status =
217226
Unix.process_status =
@@ -256,7 +265,10 @@ val system : string -> process_status Lwt.t
256265
(** Executes the given command, waits until it terminates, and
257266
return its termination status. The string is interpreted by the
258267
shell [/bin/sh] on Unix and [cmd.exe] on Windows. The result
259-
[WEXITED 127] indicates that the shell couldn't be executed. *)
268+
[WEXITED 127] indicates that the shell couldn't be executed.
269+
270+
The function uses {!fork} internally. As a result, this function is
271+
brittle. See all the warnings relating to [fork] for more details. *)
260272

261273
(** {2 Basic file input/output} *)
262274

@@ -1278,98 +1290,59 @@ val tcflow : file_descr -> flow_action -> unit Lwt.t
12781290

12791291

12801292

1281-
(** {2 Configuration (deprecated)} *)
1293+
(** {2 Configuration} *)
12821294

12831295
(** For system calls that cannot be made asynchronously, Lwt uses one
12841296
of the following method: *)
12851297
type async_method =
12861298
| Async_none
12871299
(** System calls are made synchronously, and may block the
1288-
entire program. *)
1300+
entire program.
1301+
1302+
The main use cases for this are:
1303+
- debugging (execution is simpler)
1304+
- working with fork and exec (which are not thread-safe)
1305+
- when calling specific blocking I/O which is known to be fast *)
12891306
| Async_detach
12901307
(** System calls are made in another system thread, thus without
12911308
blocking other Lwt promises. The drawback is that it may
12921309
degrade performance in some cases.
12931310
12941311
This is the default. *)
1295-
| Async_switch
1296-
[@ocaml.deprecated " Use Lwt_unix.Async_detach."]
1297-
(** @deprecated A synonym for [Async_detach]. This was a
1298-
different method in the past. *)
12991312

13001313
val default_async_method : unit -> async_method
1301-
[@@ocaml.deprecated
1302-
" Will always return Async_detach in Lwt >= 5.0.0. See
1303-
https://github.com/ocsigen/lwt/issues/572"]
13041314
(** Returns the default async method.
13051315
13061316
This can be initialized using the environment variable
1307-
["LWT_ASYNC_METHOD"] with possible values ["none"],
1308-
["detach"] and ["switch"].
1309-
1310-
@deprecated Will always return [Async_detach] in Lwt 5.0.0. *)
1317+
["LWT_ASYNC_METHOD"] with possible values ["none"] and
1318+
["detach"].
1319+
*)
13111320

13121321
val set_default_async_method : async_method -> unit
1313-
[@@ocaml.deprecated
1314-
" Will be a no-op in Lwt >= 5.0.0. See
1315-
https://github.com/ocsigen/lwt/issues/572"]
1316-
(** Sets the default async method.
1317-
1318-
@deprecated Will be a no-op in Lwt 5.0.0. *)
1322+
(** Sets the default async method. *)
13191323

13201324
val async_method : unit -> async_method
1321-
[@@ocaml.deprecated
1322-
" Will always return Async_detach in Lwt >= 5.0.0. See
1323-
https://github.com/ocsigen/lwt/issues/572"]
13241325
(** [async_method ()] returns the async method used in the current
1325-
thread.
1326-
1327-
@deprecated Will always return [Async_detach] in Lwt 5.0.0. *)
1326+
thread. *)
13281327

13291328
val async_method_key : async_method Lwt.key
1330-
[@@ocaml.deprecated
1331-
" Will be ignored in Lwt >= 5.0.0. See
1332-
https://github.com/ocsigen/lwt/issues/572"]
1333-
(** The key for storing the local async method.
1334-
1335-
@deprecated Will be ignored in Lwt 5.0.0. *)
1329+
(** The key for storing the local async method. *)
13361330

13371331
val with_async_none : (unit -> 'a) -> 'a
1338-
[@@ocaml.deprecated
1339-
" Will have no effect in Lwt >= 5.0.0. See
1340-
https://github.com/ocsigen/lwt/issues/572"]
13411332
(** [with_async_none f] is a shorthand for:
13421333
13431334
{[
13441335
Lwt.with_value async_method_key (Some Async_none) f
13451336
]}
1346-
1347-
@deprecated Will have no effect in Lwt 5.0.0. *)
1337+
*)
13481338

13491339
val with_async_detach : (unit -> 'a) -> 'a
1350-
[@@ocaml.deprecated
1351-
" Will have no effect in Lwt >= 5.0.0. See
1352-
https://github.com/ocsigen/lwt/issues/572"]
13531340
(** [with_async_detach f] is a shorthand for:
13541341
13551342
{[
13561343
Lwt.with_value async_method_key (Some Async_detach) f
13571344
]}
1358-
1359-
@deprecated Will have no effect in Lwt 5.0.0. *)
1360-
1361-
val with_async_switch : (unit -> 'a) -> 'a
1362-
[@@ocaml.deprecated
1363-
" Will have no effect in Lwt >= 5.0.0. See
1364-
https://github.com/ocsigen/lwt/issues/572"]
1365-
(** [with_async_switch f] is a shorthand for:
1366-
1367-
{[
1368-
Lwt.with_value async_method_key (Some Async_switch) f
1369-
]}
1370-
1371-
@deprecated Will have no effect in Lwt 5.0.0. *)
1372-
1345+
*)
13731346

13741347

13751348
(** {2 Low-level interaction} *)

0 commit comments

Comments
 (0)