From 4a6da2ce57845cacbc1d72fc8903eaa29fe76683 Mon Sep 17 00:00:00 2001 From: Jonathan Worthington Date: Fri, 20 Oct 2017 16:50:42 +0200 Subject: [PATCH] Test `hyper for`, `race for`, and `for` semantics --- S07-hyperrace/for.t | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 S07-hyperrace/for.t diff --git a/S07-hyperrace/for.t b/S07-hyperrace/for.t new file mode 100644 index 0000000000..3d99cedd57 --- /dev/null +++ b/S07-hyperrace/for.t @@ -0,0 +1,58 @@ +use v6; +use Test; + +plan 6; + +{ + my \rs = (^10000).race.map(* + 1); + my $main-thread = $*THREAD.id; + my $saw-another-thread = False; + for rs { + $saw-another-thread = True if $*THREAD.id != $main-thread; + } + nok $saw-another-thread, 'Plain for loop sequentially iterates a RaceSeq'; +} + +{ + my \hs = (^10000).hyper.map(* + 1); + my $main-thread = $*THREAD.id; + my $saw-another-thread = False; + for hs { + $saw-another-thread = True if $*THREAD.id != $main-thread; + } + nok $saw-another-thread, 'Plain for loop sequentially iterates a HyperSeq'; +} + +{ + my \rs = (^10000).race.map(* + 1); + my $main-thread = $*THREAD.id; + my $saw-another-thread = False; + $saw-another-thread = True if $*THREAD.id != $main-thread for rs; + nok $saw-another-thread, 'Plain postfix for loop sequentially iterates a RaceSeq'; +} + +{ + my \hs = (^10000).hyper.map(* + 1); + my $main-thread = $*THREAD.id; + my $saw-another-thread = False; + $saw-another-thread = True if $*THREAD.id != $main-thread for hs; + nok $saw-another-thread, 'Plain postfix for loop sequentially iterates a HyperSeq'; +} + +{ + my $main-thread = $*THREAD.id; + my $saw-another-thread = False; + race for ^10000 { + $saw-another-thread = True if $*THREAD.id != $main-thread; + } + ok $saw-another-thread, 'A race for loop runs the body over threads'; +} + +{ + my $main-thread = $*THREAD.id; + my $saw-another-thread = False; + hyper for ^10000 { + $saw-another-thread = True if $*THREAD.id != $main-thread; + } + ok $saw-another-thread, 'A hyper for loop runs the body over threads'; +}