Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't exit while a domain is still running. #13190

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions testsuite/tests/lazy/lazy3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
ocamlopt_flags += " -O3 ";
*)

(* In this test we force a lazy from two concurrent domains without
synchronization. This leads to unspecified behavior but still
should not crash. Currently, the implementation raises Undefined,
and that's what we test here.

Note: due to a bug in the current implementation of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is likely to go out of sync. When we fix this bug, it is likely that we will not fix this comment as the existing tools (such as running the testsuite) won't help catch this.

My preference should be to remove this Note altogether, with the idea that memory cleanup at exit feature will have a recommendation something to the effect of "When used in a multi-domain program, it is undefined behaviour not to join all the spawned domain before the main domain terminates. Undefined behaviour here includes crashes.".

Additionally, It is not clear what this bug is. If we are keeping this comment in some form, it would be useful to link to the bug report somewhere (or the wip PR #12964).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, so I removed the merge-me label for now. (I am not patient enough to wait for @damiendoligez to update his PR, but then I am not motivated enough to fix the comment myself, so for now let's just wait.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to go ahead and merge, and will remove the Note as recommended in trunk.

cleanup-at-exit, we must be careful to join d1 before we exit the
main domain at the end of the program.
*)


let f count =
let _n = (Domain.self ():> int) in
let r = ref 0 in
Expand All @@ -17,11 +28,12 @@ let main () =
let _n = (Domain.self ():> int) in
Lazy.force l)
in
let n2 = Lazy.force l in
let n2 = try Some (Lazy.force l) with Lazy.Undefined -> None in
let n1 = Domain.join d1 in
(n1, n2)

let _ =
match main () with
| (n1, n2) -> Printf.printf "n1=%d n2=%d\n" n1 n2
| (n1, Some n2) -> Printf.printf "n1=%d n2=%d\n" n1 n2
| (_, None) -> print_endline "Undefined"
| exception Lazy.Undefined -> print_endline "Undefined"
Loading