-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5362 from Vincent-lau/private/shul2/async-race
- Loading branch information
Showing
11 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
sexplib0 | ||
uri | ||
xapi-log | ||
xapi-stdext-threads | ||
) | ||
(preprocess (pps ppx_deriving_rpc ppx_sexp_conv)) | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module type MTEST = sig | ||
type +'a io | ||
|
||
val mutex_provides_mutal_exclusion : unit -> unit io | ||
end | ||
|
||
module Make = | ||
functor | ||
(M : S.BACKEND) | ||
-> | ||
struct | ||
open M.IO | ||
|
||
type 'a io = 'a M.IO.t | ||
|
||
let ocaml_lock = Mutex.create () | ||
|
||
let mu = M.Mutex.create () | ||
|
||
let cond = M.Condition.create () | ||
|
||
let broadcast () = M.Condition.broadcast cond () | ||
|
||
let mutex_provides_mutal_exclusion () : unit io = | ||
let promises = | ||
List.init 100 (fun _ -> | ||
M.Condition.wait cond >>= fun () -> | ||
M.Mutex.with_lock mu (fun () -> | ||
M.IO.return_unit >>= fun () -> | ||
(* the with_lock implementation should ensure that only one | ||
monad can try to acquire this lock *) | ||
assert (Mutex.try_lock ocaml_lock) ; | ||
M.IO.return_unit >>= fun () -> | ||
Mutex.unlock ocaml_lock ; M.IO.return_unit | ||
) | ||
) | ||
in | ||
broadcast () ; | ||
ignore @@ all promises ; | ||
Printf.printf "%s test.\n" (M.whoami ()) ; | ||
M.IO.return_unit | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
open Core | ||
open Async | ||
open Message_switch_async | ||
|
||
let ( >>= ) = Deferred.( >>= ) | ||
|
||
let test_async_lock () = Protocol_async.Mtest.mutex_provides_mutal_exclusion () | ||
|
||
let () = | ||
don't_wait_for | ||
(test_async_lock () >>= fun () -> shutdown 0 ; Deferred.return ()) | ||
|
||
let () = never_returns (Scheduler.go ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
open Message_switch_lwt | ||
|
||
let test_lwt_lock = Protocol_lwt.Mtest.mutex_provides_mutal_exclusion () | ||
|
||
let () = Lwt_main.run test_lwt_lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters