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 >
Text File  |  1989-12-23  |  1KB  |  74 lines

  1. .( Loading Channel test...) cr
  2.  
  3. #include multi_tasking.f83
  4.  
  5. structures multi-tasking
  6.  
  7. ONE-TO-ONE CHAN binding
  8.  
  9. : bind ( x -- )  binding receive swap ! ;
  10. : wire ( x -- )  binding send ;
  11. : WIRE ( -- )    ONE-TO-ONE CHAN this wire ;
  12.  
  13. .( 1: Use a task and three channels to add two numbers) cr
  14.  
  15. 100 100 task.type ADDER
  16.   ptr a
  17.   ptr b
  18.   ptr c
  19. task.body
  20.   a bind b bind c bind
  21.   begin
  22.     a @ receive b @ receive
  23.     +
  24.     c @ send
  25.   again
  26. task.end
  27.  
  28. ADDER a1 WIRE x WIRE y WIRE z
  29.  
  30. : add2 ( x y -- z=x+y)  x send y send z receive ;
  31.  
  32. who 100 90 add2 . cr
  33.  
  34. .( 2: Add an other adder and add three numbers using two tasks) cr
  35.  
  36. ADDER a2 z wire WIRE a WIRE b
  37.  
  38. : add3 ( x y z -- x+y+z)  x send y send a send b receive ;
  39.  
  40. who 1000 100 90 add3 . cr
  41.  
  42. .( 3: Run factorial as a task with two channels) cr
  43.  
  44. 100 100 task.type FAC
  45.   ptr a
  46.   ptr b
  47. task.body 
  48.   a bind b bind
  49.   begin
  50.     1 a @ receive 1+ 1 do
  51.       i * detach
  52.     loop
  53.     b @ send
  54.   again
  55. task.end
  56.  
  57. FAC f WIRE n WIRE n!
  58.  
  59. : fac ( n -- n!)
  60.   n send
  61.   ." I'm waiting.."
  62.   begin
  63.     n! ?avail not
  64.   while
  65.     ." .."
  66.     detach
  67.   repeat
  68.   ." done" cr
  69.   n! receive ;
  70.  
  71. who 10 fac . cr
  72.  
  73. forth only
  74.