Skip to content

Commit

Permalink
Try harder to return an optimal index and allow slack in test
Browse files Browse the repository at this point in the history
  • Loading branch information
polytypic committed Dec 24, 2023
1 parent 1253ebe commit cd273c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.ocaml5.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ open struct
t.on_first_get t domain
end
else Index_allocator.release t.index_allocator index;
new_index
instantaneous_domain_index t domain
end
else begin
Index_allocator.release t.index_allocator new_index;
Expand Down
3 changes: 2 additions & 1 deletion test/Multicore_magic_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ let test_instantaneous_domain_index () =
let module Atomic = Multicore_magic.Transparent_atomic in
let stress () =
let n_domains = 7 in
let slack = 1 in
let num_started = Atomic.make 0 |> Multicore_magic.copy_as_padded in
let num_exited = Atomic.make 0 |> Multicore_magic.copy_as_padded in
let failed = ref false |> Multicore_magic.copy_as_padded in
Expand All @@ -115,7 +116,7 @@ let test_instantaneous_domain_index () =
let num_exited = Atomic.get num_exited in
let i = Multicore_magic.instantaneous_domain_index () in
let n = Atomic.get num_started - num_exited in
if i < 0 || n < i then failed := true
if i < 0 || n + slack < i then failed := true
in

let domain () =
Expand Down

0 comments on commit cd273c6

Please sign in to comment.