langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
14
Task/Concurrent-computing/OCaml/concurrent-computing.ocaml
Normal file
14
Task/Concurrent-computing/OCaml/concurrent-computing.ocaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#directory "+threads"
|
||||
#load "unix.cma"
|
||||
#load "threads.cma"
|
||||
|
||||
let sleepy_print msg =
|
||||
Unix.sleep (Random.int 4);
|
||||
print_endline msg
|
||||
|
||||
let threads =
|
||||
List.map (Thread.create sleepy_print) ["Enjoy"; "Rosetta"; "Code"]
|
||||
|
||||
let () =
|
||||
Random.self_init ();
|
||||
List.iter (Thread.join) threads
|
||||
27
Task/Concurrent-computing/Objeck/concurrent-computing.objeck
Normal file
27
Task/Concurrent-computing/Objeck/concurrent-computing.objeck
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
bundle Default {
|
||||
class MyThread from Thread {
|
||||
New(name : String) {
|
||||
Parent(name);
|
||||
}
|
||||
|
||||
method : public : Run(param : Base) ~ Nil {
|
||||
string := param->As(String);
|
||||
string->PrintLine();
|
||||
}
|
||||
}
|
||||
|
||||
class Concurrent {
|
||||
New() {
|
||||
}
|
||||
|
||||
function : Main(args : System.String[]) ~ Nil {
|
||||
t0 := MyThread->New("t0");
|
||||
t1 := MyThread->New("t1");
|
||||
t2 := MyThread->New("t2");
|
||||
|
||||
t0->Execute("Enjoy"->As(Base));
|
||||
t1->Execute("Rosetta"->As(Base));
|
||||
t2->Execute("Code"->As(Base));
|
||||
}
|
||||
}
|
||||
}
|
||||
5
Task/Concurrent-computing/Oz/concurrent-computing.oz
Normal file
5
Task/Concurrent-computing/Oz/concurrent-computing.oz
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
for Msg in ["Enjoy" "Rosetta" "Code"] do
|
||||
thread
|
||||
{System.showInfo Msg}
|
||||
end
|
||||
end
|
||||
17
Task/Concurrent-computing/PARI-GP/concurrent-computing.pari
Normal file
17
Task/Concurrent-computing/PARI-GP/concurrent-computing.pari
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
void
|
||||
foo()
|
||||
{
|
||||
if (pari_daemon()) {
|
||||
// Original
|
||||
if (pari_daemon()) {
|
||||
// Original
|
||||
pari_printf("Enjoy\n");
|
||||
} else {
|
||||
// Daemon #2
|
||||
pari_printf("Code\n");
|
||||
}
|
||||
} else {
|
||||
// Daemon #1
|
||||
pari_printf("Rosetta\n");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
my @words = <Enjoy Rosetta Code>;
|
||||
@words».say
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Rosetta
|
||||
Code
|
||||
Enjoy
|
||||
11
Task/Concurrent-computing/Pike/concurrent-computing-1.pike
Normal file
11
Task/Concurrent-computing/Pike/concurrent-computing-1.pike
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
int main() {
|
||||
// Start threads and wait for them to finish
|
||||
({
|
||||
Thread.Thread(write, "Enjoy\n"),
|
||||
Thread.Thread(write, "Rosetta\n"),
|
||||
Thread.Thread(write, "Code\n")
|
||||
})->wait();
|
||||
|
||||
// Exit program
|
||||
exit(0);
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
int main(int argc, array argv)
|
||||
{
|
||||
call_out(write, random(1.0), "Enjoy\n");
|
||||
call_out(write, random(1.0), "Rosetta\n");
|
||||
call_out(write, random(1.0), "Code\n");
|
||||
call_out(exit, 1, 0);
|
||||
return -1; // return -1 starts the backend which makes Pike run until exit() is called.
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
Global mutex = CreateMutex()
|
||||
|
||||
Procedure Printer(*str)
|
||||
LockMutex(mutex)
|
||||
PrintN( PeekS(*str) )
|
||||
UnlockMutex(mutex)
|
||||
EndProcedure
|
||||
|
||||
If OpenConsole()
|
||||
LockMutex(mutex)
|
||||
thread1 = CreateThread(@Printer(), @"Enjoy")
|
||||
thread2 = CreateThread(@Printer(), @"Rosetta")
|
||||
thread3 = CreateThread(@Printer(), @"Code")
|
||||
UnlockMutex(mutex)
|
||||
|
||||
WaitThread(thread1)
|
||||
WaitThread(thread2)
|
||||
WaitThread(thread3)
|
||||
|
||||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
|
||||
Input()
|
||||
|
||||
CloseConsole()
|
||||
EndIf
|
||||
|
||||
FreeMutex(mutex)
|
||||
10
Task/Concurrent-computing/Raven/concurrent-computing.raven
Normal file
10
Task/Concurrent-computing/Raven/concurrent-computing.raven
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[ 'Enjoy' 'Rosetta' 'Code' ] as $words
|
||||
|
||||
thread talker
|
||||
$words pop "%s\n"
|
||||
repeat dup print
|
||||
500 choose ms
|
||||
|
||||
talker as a
|
||||
talker as b
|
||||
talker as c
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Main(0,0)
|
||||
|:
|
||||
Print["Enjoy"]
|
||||
Print["Rosetta"]
|
||||
Print["Code"]
|
||||
:|
|
||||
|
|
@ -0,0 +1 @@
|
|||
(echo "Enjoy" & echo "Rosetta"& echo "Code"&)
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
Imports System.Threading
|
||||
|
||||
Module Module1
|
||||
Public rnd As New Random
|
||||
|
||||
Sub Main()
|
||||
Dim t1 As New Thread(AddressOf Foo)
|
||||
Dim t2 As New Thread(AddressOf Foo)
|
||||
Dim t3 As New Thread(AddressOf Foo)
|
||||
|
||||
t1.Start("Enjoy")
|
||||
t2.Start("Rosetta")
|
||||
t3.Start("Code")
|
||||
|
||||
t1.Join()
|
||||
t2.Join()
|
||||
t3.Join()
|
||||
|
||||
End Sub
|
||||
|
||||
Sub Foo(ByVal state As Object)
|
||||
Thread.Sleep(rnd.Next(1000))
|
||||
Console.WriteLine(state)
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
Loading…
Add table
Add a link
Reference in a new issue