-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flambda-backend: Introduce an API to swap the runtime lock for a diff…
…erent lock. (#1365) See caml_switch_runtime_locking_scheme in threads.h
- Loading branch information
Showing
6 changed files
with
303 additions
and
24 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
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 @@ | ||
(* TEST | ||
modules = "swapgil_stubs.c" | ||
* hassysthreads | ||
include systhreads | ||
** hasunix | ||
*** native | ||
*) | ||
|
||
let counter = ref 0 | ||
|
||
external blocking_section : unit -> unit = "blocking_section" | ||
|
||
type c_thread | ||
external create_c_thread : (unit -> unit) -> c_thread = "create_c_thread" | ||
external join_c_thread : c_thread -> unit = "join_c_thread" | ||
|
||
external swap_gil : unit -> unit = "swap_gil" | ||
|
||
let threadfn () = | ||
for i = 1 to 1_000 do | ||
incr counter; | ||
let junk = Sys.opaque_identity (ref !counter) in | ||
ignore junk; | ||
match i mod 100, i mod 10 with | ||
| _, 0 -> Thread.yield () | ||
| _, 1 -> blocking_section () | ||
| 22, _ -> Gc.minor () | ||
| _, 3 -> swap_gil () | ||
| _ -> () | ||
done | ||
|
||
let () = | ||
let open Either in | ||
let threads = | ||
List.init 40 (fun i -> | ||
if i land 1 = 0 then | ||
Left (Thread.create threadfn ()) | ||
else | ||
Right (create_c_thread threadfn)) | ||
in | ||
List.iter (function Left th -> Thread.join th | Right ct -> join_c_thread ct) threads; | ||
Printf.printf "%d\n" !counter |
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 @@ | ||
40000 |
Oops, something went wrong.