forked from ocaml/ocaml
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Improved Thread.yield / thread preemption (ocaml#1533)
* PR#7669 : under Linux, use nanosleep(1) as the implementation of Thread.yield. This results in a scheduling of threads that is much more fair than before. * Add a testpreempt.ml test to check that thread preemption is fair. This is not yet the case for the Windows ports, so disable the test on Windows. * Use Unix.sleepf as an implementation of Thread.delay instead of Unix.select. Unix.sleepf can have better resolution than Unix.select. * Fix signal.ml test Add "wait" in the runner shell script in order to make sure that the process has properly exited before its output is compared with the reference output.
- Loading branch information
Showing
6 changed files
with
41 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
let rec generate_list n = | ||
let rec aux acc = function | ||
| 0 -> acc | ||
| n -> aux (float n :: acc) (n-1) | ||
in | ||
aux [] n | ||
|
||
let rec long_computation time0 = | ||
let long_list = generate_list 100000 in | ||
let res = List.length (List.rev_map sin long_list) in | ||
if Sys.time () -. time0 > 2. then | ||
Printf.printf "Long computation result: %d\n%!" res | ||
else long_computation time0 | ||
|
||
let interaction () = | ||
Thread.delay 0.1; | ||
Printf.printf "Interaction 1\n"; | ||
Thread.delay 0.1; | ||
Printf.printf "Interaction 2\n" | ||
|
||
let () = | ||
ignore (Thread.create interaction ()); | ||
long_computation (Sys.time ()) |
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 @@ | ||
# On Windows, we use Sleep(0) for triggering preemption of threads. | ||
# However, this does not seem very reliable, so that this test fails | ||
# on some Windows configurations. See GPR #1533. | ||
|
||
test "$OS" != "Windows_NT" |
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,3 @@ | ||
Interaction 1 | ||
Interaction 2 | ||
Long computation result: 100000 |
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 |
---|---|---|
|
@@ -17,3 +17,4 @@ $RUNTIME ./program >signal.result & | |
pid=$! | ||
sleep 2 | ||
test -e ./sigint.exe && ./sigint $pid || kill -INT $pid | ||
wait |