Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -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)))
|
||||
10
Task/Metered-concurrency/Oforth/metered-concurrency-1.oforth
Normal file
10
Task/Metered-concurrency/Oforth/metered-concurrency-1.oforth
Normal 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 ;
|
||||
11
Task/Metered-concurrency/Oforth/metered-concurrency-2.oforth
Normal file
11
Task/Metered-concurrency/Oforth/metered-concurrency-2.oforth
Normal 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 ] & ] ;
|
||||
Loading…
Add table
Add a link
Reference in a new issue