Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,13 @@
(lib 'tasks) ;; use the tasks library
(define (tprint line ) ;; task definition
(writeln _TASK line)
#f )
(for-each task-run ;; run three // tasks
(map (curry make-task tprint) '(Enjoy Rosetta code )))
#task:id:66:running Rosetta
#task:id:67:running code
#task:id:65:running Enjoy

View file

@ -0,0 +1,29 @@
' FB 1.05.0 Win64
' Compiled with -mt switch (to use threadsafe runtiume)
' The 'ThreadCall' functionality in FB is based internally on LibFFi (see [https://github.com/libffi/libffi/blob/master/LICENSE] for license)
Sub thread1()
Print "Enjoy"
End Sub
Sub thread2()
Print "Rosetta"
End Sub
Sub thread3()
Print "Code"
End Sub
Print "Press any key to print next batch of 3 strings or ESC to quit"
Print
Do
Dim t1 As Any Ptr = ThreadCall thread1
Dim t2 As Any Ptr = ThreadCall thread2
Dim t3 As Any Ptr = ThreadCall thread3
ThreadWait t1
ThreadWait t2
ThreadWait t3
Print
Sleep
Loop While Inkey <> Chr(27)

View file

@ -0,0 +1,26 @@
;;;
;;; This is a straight port of the Erlang version.
;;;
;;; You can run this under the LFE REPL as follows:
;;;
;;; (slurp "concurrent-computing.lfe")
;;; (start)
;;;
(defmodule concurrent-computing
(export (start 0)))
(defun start ()
(lc ((<- word '("Enjoy" "Rosetta" "Code")))
(spawn (lambda () (say (self) word))))
(wait 2)
'ok)
(defun say (pid word)
(lfe_io:format "~p~n" (list word))
(! pid 'done))
(defun wait (n)
(receive
('done (case n
(0 0)
(_n (wait (- n 1)))))))

View file

@ -0,0 +1,10 @@
const str = ["Enjoy", "Rosetta", "Code"]
var thr: array[3, TThread[int32]]
proc f(i) {.thread.} =
echo str[i]
for i in 0..thr.high:
createThread(thr[i], f, int32(i))
joinThreads(thr)

View file

@ -0,0 +1,4 @@
const str = ["Enjoy", "Rosetta", "Code"]
for i in 0||2:
echo str[i]

View file

@ -0,0 +1,9 @@
import threadpool
const str = ["Enjoy", "Rosetta", "Code"]
proc f(i) {.thread.} =
echo str[i]
for i in 0..str.high:
spawn f(i)
sync()

View file

@ -0,0 +1,3 @@
#[ "Enjoy" println ] &
#[ "Rosetta" println ] &
#[ "Code" println ] &

View file

@ -0,0 +1 @@
[ "Enjoy", "Rosetta", "Code" ] mapParallel(#[ dup . size ])

View file

@ -0,0 +1,15 @@
procedure echo(string s)
sleep(rand(100)/100)
enter_cs()
puts(1,s)
puts(1,'\n')
leave_cs()
end procedure
constant threads = {create_thread(routine_id("echo"),{"Enjoy"}),
create_thread(routine_id("echo"),{"Rosetta"}),
create_thread(routine_id("echo"),{"Code"})}
wait_thread(threads)
puts(1,"done")
{} = wait_key()

View file

@ -0,0 +1,7 @@
var a = <Enjoy Rosetta Code>
a.map{|str|
{ Sys.sleep(1.rand)
say str
}.fork
}.map{|thr| thr.wait }

View file

@ -0,0 +1,11 @@
import Foundation
let myList = ["Enjoy", "Rosetta", "Code"]
for word in myList {
dispatch_async(dispatch_get_global_queue(0, 0)) {
NSLog(word)
}
}
dispatch_main()