@@ -4,17 +4,19 @@ module Atomic = Dscheck.TracedAtomic
44
55type conc_list = { value : int ; next : conc_list option }
66
7- let rec add_node list_head n =
7+ let rec add_node ~ bug list_head n =
88 (* try to add a new node to head *)
99 let old_head = Atomic. get list_head in
1010 let new_node = { value = n ; next = (Some old_head) } in
1111 (* introduce bug *)
12- if Atomic. get list_head = old_head then begin
12+ if bug && Atomic. get list_head = old_head then begin
1313 Atomic. set list_head new_node;
1414 true
1515 end
16+ else if Atomic. compare_and_set list_head old_head new_node
17+ then true
1618 else
17- add_node list_head n
19+ add_node ~bug list_head n
1820
1921let check_node list_head n =
2022 let rec check_from_node node =
@@ -28,14 +30,14 @@ let check_node list_head n =
2830 (* try to find the node *)
2931 check_from_node (Atomic. get list_head)
3032
31- let add_and_check list_head n () =
32- assert (add_node list_head n);
33+ let add_and_check ~ bug list_head n () =
34+ assert (add_node ~bug list_head n);
3335 assert (check_node list_head n)
3436
35- let create_test upto () =
37+ let create_test ~ buggy upto () =
3638 let list_head = Atomic. make { value = 0 ; next = None } in
3739 for x = 1 to upto do
38- Atomic. spawn (add_and_check list_head x);
40+ Atomic. spawn (add_and_check ~bug: (x = buggy) list_head x);
3941 done ;
4042 Atomic. final (fun () ->
4143 for x = 1 to upto do
@@ -44,4 +46,4 @@ let create_test upto () =
4446 )
4547
4648let () =
47- Atomic. trace (create_test 8 )
49+ Atomic. trace (create_test ~buggy: 2 4 )
0 commit comments