Skip to content

Commit 489e7ca

Browse files
authored
Merge pull request #585 from ocaml/thread-safety
Thread safety updates
2 parents 78b595f + 23016ac commit 489e7ca

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

lib/mark_infos.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ type t = int array
55
let make marks =
66
let len = 1 + List.fold_left ~f:(fun ma (i, _) -> max ma i) ~init:(-1) marks in
77
let t = Array.make len (-1) in
8-
List.iter ~f:(fun (i, v) -> t.(i) <- v) marks;
8+
let set (i, v) = t.(i) <- v in
9+
List.iter ~f:set marks;
910
t
1011
;;
1112

lib/pmark.ml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ module Pmark = struct
33

44
let equal (x : int) (y : int) = x = y
55
let compare (x : int) (y : int) = compare x y
6-
let r = ref 0
7-
8-
let gen () =
9-
incr r;
10-
!r
11-
;;
12-
6+
let r = Atomic.make 1
7+
let gen () = Atomic.fetch_and_add r 1
138
let pp = Format.pp_print_int
149
end
1510

lib_test/concurrency/suppress.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ race_top:^camlRe__Automata.status
1616

1717
# Race within Compile.final
1818
race_top:^camlRe__Compile.final
19+
20+
# Spurious data race due to the two-step initialization in Mark_info.make
21+
# (between Mark_info.make and other functions in module Mark_infos)
22+
race_top:^camlRe__Mark_infos.set

lib_test/concurrency/test.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ let execute ~short re a =
8181
(inverse_permutation a)
8282
(Array.map
8383
(fun i ->
84-
try Some (Re.exec ~pos:(if short then 30 - 7 else 0) re strings.(i)) with
84+
try
85+
Some
86+
(Re.Group.all_offset
87+
@@ Re.exec ~pos:(if short then 30 - 7 else 0) re strings.(i))
88+
with
8589
| Not_found -> None)
8690
a)
8791
;;
8892

89-
let compare_groups g g' = Re.Group.(all_offset g = all_offset g')
93+
let compare_groups g g' = g = g'
9094

9195
let concurrent f f' =
9296
let barrier = Barrier.create 2 in

0 commit comments

Comments
 (0)