Skip to content

Commit

Permalink
fix(stdune): fix TSAN warning in wait4_stubs (ocaml#10554)
Browse files Browse the repository at this point in the history
Fixes ocaml#10553

Quoting @jmid, using a local variable without the runtime lock in place,
is against the rules. For integer values, sometimes the rules are bent,
but this is not a good idea. See ocaml/ocaml#12737.

Signed-off-by: Etienne Millon <me@emillon.org>
  • Loading branch information
emillon committed May 24, 2024
1 parent a1d7258 commit 62a26da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/changes/10554.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- fix TSAN warning in wait4 stubs (#10554, fixes #10553, @emillon)
5 changes: 3 additions & 2 deletions otherlibs/stdune/src/wait4_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ value dune_wait4(value v_pid, value flags) {
CAMLparam2(v_pid, flags);
CAMLlocal2(times, res);

int pid, status, cv_flags;
int status, cv_flags;
struct timeval tp;
cv_flags = caml_convert_flag_list(flags, wait_flag_table);
pid_t pid = Int_val(v_pid);

struct rusage ru;

caml_enter_blocking_section();
// returns the pid of the terminated process, or -1 on error
pid = wait4(Int_val(v_pid), &status, cv_flags, &ru);
pid = wait4(pid, &status, cv_flags, &ru);
gettimeofday(&tp, NULL);
caml_leave_blocking_section();
if (pid == -1)
Expand Down

0 comments on commit 62a26da

Please sign in to comment.