Created
July 31, 2020 15:57
-
-
Save JJ/2c7f92a7de0729337c89f497ccf3758d to your computer and use it in GitHub Desktop.
Using threads to compute primes in an interval
This file contains hidden or 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
#!/usr/bin/env raku | |
constant $interval = 100000; | |
my @threads = (^10).map: -> $i { | |
Thread.start( | |
name => "Checking primes from {$i * $interval } to { ($i+1)*$interval}", | |
sub { | |
for ($i * $interval)..^(($i+1)*$interval) -> $n { | |
next if ( $n %% 2 ) | ( $n %% 3 ) | ($n %% 5 ); | |
say "Prime $n found in $*THREAD" if $n.is-prime; | |
} | |
}, | |
); | |
} | |
.finish for @threads; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment