Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
17
Task/Concurrent-computing/Ada/concurrent-computing.adb
Normal file
17
Task/Concurrent-computing/Ada/concurrent-computing.adb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
with Ada.Text_IO, Ada.Numerics.Float_Random;
|
||||
|
||||
procedure Concurrent_Hello is
|
||||
type Messages is (Enjoy, Rosetta, Code);
|
||||
task type Writer (Message : Messages);
|
||||
task body Writer is
|
||||
Seed : Ada.Numerics.Float_Random.Generator;
|
||||
begin
|
||||
Ada.Numerics.Float_Random.Reset (Seed); -- time-dependent, see ARM A.5.2
|
||||
delay Duration (Ada.Numerics.Float_Random.Random (Seed));
|
||||
Ada.Text_IO.Put_Line (Messages'Image(Message));
|
||||
end Writer;
|
||||
Taks: array(Messages) of access Writer -- 3 Writer tasks will immediately run
|
||||
:= (new Writer(Enjoy), new Writer(Rosetta), new Writer(Code));
|
||||
begin
|
||||
null; -- the "environment task" doesn't need to do anything
|
||||
end Concurrent_Hello;
|
||||
|
|
@ -1,17 +1,12 @@
|
|||
require "channel"
|
||||
require "fiber"
|
||||
require "random"
|
||||
require "wait_group"
|
||||
|
||||
done = Channel(Nil).new
|
||||
wg = WaitGroup.new
|
||||
|
||||
"Enjoy Rosetta Code".split.map do |x|
|
||||
spawn do
|
||||
wg.spawn do
|
||||
sleep Random.new.rand(0..500).milliseconds
|
||||
puts x
|
||||
done.send nil
|
||||
end
|
||||
end
|
||||
|
||||
3.times do
|
||||
done.receive
|
||||
end
|
||||
wg.wait
|
||||
|
|
|
|||
17
Task/Concurrent-computing/Euphoria/concurrent-computing.eu
Normal file
17
Task/Concurrent-computing/Euphoria/concurrent-computing.eu
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
procedure echo(sequence s)
|
||||
puts(1,s)
|
||||
puts(1,'\n')
|
||||
end procedure
|
||||
|
||||
atom task1,task2,task3
|
||||
|
||||
task1 = task_create(routine_id("echo"),{"Enjoy"})
|
||||
task_schedule(task1,1)
|
||||
|
||||
task2 = task_create(routine_id("echo"),{"Rosetta"})
|
||||
task_schedule(task2,1)
|
||||
|
||||
task3 = task_create(routine_id("echo"),{"Code"})
|
||||
task_schedule(task3,1)
|
||||
|
||||
task_yield()
|
||||
8
Task/Concurrent-computing/Perl/concurrent-computing-3.pl
Normal file
8
Task/Concurrent-computing/Perl/concurrent-computing-3.pl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/perl -l
|
||||
|
||||
use strict; # https://rosettacode.org/wiki/Concurrent_computing
|
||||
use warnings;
|
||||
use Time::HiRes qw( sleep );
|
||||
|
||||
fork or sleep(rand), exit print for qw(Enjoy Rosetta Code);
|
||||
1 while wait > 0;
|
||||
16
Task/Concurrent-computing/Pluto/concurrent-computing.pluto
Normal file
16
Task/Concurrent-computing/Pluto/concurrent-computing.pluto
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
local words = {"Enjoy", "Rosetta", "Code"}
|
||||
for h = 1, 3 do
|
||||
local threads = {}
|
||||
for i = 1, 3 do threads[i] = coroutine.create(|| -> print(words[i])) end
|
||||
local called = {false, false, false}
|
||||
local j = 0
|
||||
while j < 3 do
|
||||
local k = math.random(1, 3)
|
||||
if !called[k] then
|
||||
coroutine.resume(threads[k])
|
||||
called[k] = true
|
||||
j += 1
|
||||
end
|
||||
end
|
||||
print()
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
$Strings = "Enjoy","Rosetta","Code"
|
||||
|
||||
$SB = {param($String)Write-Output $String}
|
||||
|
||||
foreach($String in $Strings) {
|
||||
Start-Job -ScriptBlock $SB -ArgumentList $String | Out-Null
|
||||
}
|
||||
|
||||
Get-Job | Wait-Job | Receive-Job
|
||||
Get-Job | Remove-Job
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
$Strings = "Enjoy","Rosetta","Code"
|
||||
|
||||
$SB = {param($String)Write-Output $String}
|
||||
|
||||
$Pool = [RunspaceFactory]::CreateRunspacePool(1, 3)
|
||||
$Pool.ApartmentState = "STA"
|
||||
$Pool.Open()
|
||||
foreach ($String in $Strings) {
|
||||
$Pipeline = [System.Management.Automation.PowerShell]::create()
|
||||
$Pipeline.RunspacePool = $Pool
|
||||
[void]$Pipeline.AddScript($SB).AddArgument($String)
|
||||
$AsyncHandle = $Pipeline.BeginInvoke()
|
||||
$Pipeline.EndInvoke($AsyncHandle)
|
||||
$Pipeline.Dispose()
|
||||
}
|
||||
$Pool.Close()
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
import time
|
||||
import rand
|
||||
import rand.pcg32
|
||||
import rand.seed
|
||||
|
||||
fn main() {
|
||||
words := ['Enjoy', 'Rosetta', 'Code']
|
||||
seed_u64 := u64(time.now().unix_time_milli())
|
||||
seed_u64 := u64(time.now().unix_milli())
|
||||
q := chan string{}
|
||||
for i, w in words {
|
||||
go fn (q chan string, w string, seed_u64 u64) {
|
||||
|
|
@ -13,7 +12,7 @@ fn main() {
|
|||
time_seed := seed.time_seed_array(2)
|
||||
seed_arr := [u32(seed_u64), u32(seed_u64 >> 32), time_seed[0], time_seed[1]]
|
||||
rng.seed(seed_arr)
|
||||
time.sleep(time.Duration(rng.i64n(1_000_000_000)))
|
||||
time.sleep(time.Duration(rng.u32()))
|
||||
q <- w
|
||||
}(q, w, seed_u64 + u64(i))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import time
|
||||
import rand
|
||||
import rand.pcg32
|
||||
import rand.seed
|
||||
|
||||
|
|
@ -11,7 +10,7 @@ fn main() {
|
|||
mut rng := pcg32.PCG32RNG{}
|
||||
time_seed := seed.time_seed_array(4) // the time derived array to seed the random generator
|
||||
rng.seed(time_seed)
|
||||
time.sleep(time.Duration(rng.i64n(1_000_000_000)))
|
||||
time.sleep(time.Duration(rng.u32()))
|
||||
println(w)
|
||||
}(w)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue