home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
pd6.lzh
/
TST
/
channels.tst
< prev
next >
Wrap
Text File
|
1989-12-23
|
1KB
|
74 lines
.( Loading Channel test...) cr
#include multi_tasking.f83
structures multi-tasking
ONE-TO-ONE CHAN binding
: bind ( x -- ) binding receive swap ! ;
: wire ( x -- ) binding send ;
: WIRE ( -- ) ONE-TO-ONE CHAN this wire ;
.( 1: Use a task and three channels to add two numbers) cr
100 100 task.type ADDER
ptr a
ptr b
ptr c
task.body
a bind b bind c bind
begin
a @ receive b @ receive
+
c @ send
again
task.end
ADDER a1 WIRE x WIRE y WIRE z
: add2 ( x y -- z=x+y) x send y send z receive ;
who 100 90 add2 . cr
.( 2: Add an other adder and add three numbers using two tasks) cr
ADDER a2 z wire WIRE a WIRE b
: add3 ( x y z -- x+y+z) x send y send a send b receive ;
who 1000 100 90 add3 . cr
.( 3: Run factorial as a task with two channels) cr
100 100 task.type FAC
ptr a
ptr b
task.body
a bind b bind
begin
1 a @ receive 1+ 1 do
i * detach
loop
b @ send
again
task.end
FAC f WIRE n WIRE n!
: fac ( n -- n!)
n send
." I'm waiting.."
begin
n! ?avail not
while
." .."
detach
repeat
." done" cr
n! receive ;
who 10 fac . cr
forth only