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 @@
(require 'tasks) ;; tasks library
(define (task id)
(wait S) ;; acquire, p-op
(printf "task %d acquires semaphore @ %a" id (date->time-string (current-date)))
(sleep 2000)
(signal S) ;; release, v-op
id)
(define S (make-semaphore 4)) ;; semaphore with init count 4
;; run 10 // tasks
(for ([i 10]) (task-run (make-task task i ) (random 500)))

View file

@ -0,0 +1,10 @@
import: parallel
Object Class new: Semaphore(ch)
Semaphore method: initialize(n)
Channel newSize(n) dup := ch
#[ 1 over send drop ] times(n) drop ;
Semaphore method: acquire @ch receive drop ;
Semaphore method: release 1 @ch send drop ;

View file

@ -0,0 +1,11 @@
: mytask(s)
while( true ) [
s acquire "Semaphore acquired" .cr
2000 sleep
s release "Semaphore released" .cr
] ;
: test(n)
| s i |
Semaphore new(n) ->s
10 loop: i [ #[ s mytask ] & ] ;