Rendezvous: Difference between revisions

Added PicoLisp
m (omit from Retro)
(Added PicoLisp)
Line 343:
Like in the rendezvous mechanism, parameters are not marshalled. This is because sharing immutable data between threads is safe.
In contrast to ADA, the parameters are buffered until the printer becomes ready. But with a synchronous communication mechanism, this should not cause problems.
 
=={{header|PicoLisp}}==
Rendezvous can be implemented in PicoLisp via the following function:
<lang PicoLisp>(de rendezvous (Pid . Exe)
(when
(catch '(NIL)
(tell Pid 'setq 'Rendezvous (lit (eval Exe)))
NIL )
(tell Pid 'quit @) ) ) # Raise caught error in caller</lang>
The caller invokes it in the callee via the
'[http://software-lab.de/doc/refT.html#tell tell]' interprocess communication,
and it uses 'tell' in turn to communicate results (and possible errors) back to
the caller.
 
Use case task:
<lang PicoLisp>(de printLine (Str)
(cond
((gt0 *Ink) (prinl *ID ": " Str) (dec '*Ink))
(*Backup (rendezvousPrint @ Str) T)
(T (quit "Out of Ink")) ) )
 
(de rendezvousPrint (Printer Str)
(let Rendezvous NIL
(tell Printer 'rendezvous *Pid 'printLine Str) # Call entry point
(unless (wait 6000 Rendezvous) # Block max. 1 minute
(quit "Rendezvous timed out") ) ) )
 
# Start RESERVE printer process
(unless (setq *ReservePrinter (fork))
(setq *ID 2 *Ink 5)
(wait) ) # Run forever
 
# Start MAIN printer process
(unless (setq *MainPrinter (fork))
(setq *ID 1 *Ink 5 *Backup *ReservePrinter)
(wait) )
 
# Start Humpty Dumpty process
(unless (fork)
(when
(catch '(NIL)
(for Line
(quote
"Humpty Dumpty sat on a wall."
"Humpty Dumpty had a great fall."
"All the king's horses and all the king's men"
"Couldn't put Humpty together again." )
(rendezvousPrint *MainPrinter Line) ) )
(prinl " Humpty Dumpty: " @ "!") )
(bye) )
 
# Start Mother Goose process
(unless (fork)
(when
(catch '(NIL)
(for Line
(quote
"Old Mother Goose"
"When she wanted to wander,"
"Would ride through the air"
"On a very fine gander."
"Jack's mother came in,"
"And caught the goose soon,"
"And mounting its back,"
"Flew up to the moon." )
(rendezvousPrint *MainPrinter Line) ) )
(prinl " Mother Goose: " @ "!") )
(bye) )
 
# Prepare to terminate all processes upon exit
(push '*Bye '(tell 'bye))</lang>
Output:
<pre>1: Old Mother Goose
1: Humpty Dumpty sat on a wall.
1: When she wanted to wander,
1: Humpty Dumpty had a great fall.
1: Would ride through the air
2: All the king's horses and all the king's men
2: On a very fine gander.
2: Jack's mother came in,
2: And caught the goose soon,
2: And mounting its back,
Humpty Dumpty: Out of Ink!</pre>
 
=={{header|Tcl}}==
Anonymous user