I've spent a lot of time recently trying to figure out the following:
The examples given in the Icon and Unicon books for using coexpressions to
implement a solution to a producer-consumer problem all depend on the
consumer coexp being activated before the producer coexp in order to receive
the first value transmitted by the producer coexp.
I thought that I would share my successful attempt to have a consumer
receive the first value transmitted by the producer regardless of whether it
was activated first. Basically, there is one producer and two consumers; the
consumer is chosen "randomly" (although I find that I get the same output
for every run, so something is amiss in my random selection).
procedure main( )
local t_activated, t_ce, C
t_activated := table( )
t_ce := table( )
t_ce["consumer"] :=
create {
t_activated[¤t] := &source
while write( @t_ce["producer"] )
}
t_ce["remusnoc"] :=
create {
t_activated[¤t] := &source
while write( reverse( @t_ce["producer"] ) )
}
t_ce["producer"] :=
create {
every ( "Quantum materiae" |
"materietur marmota monax" |
"si marmota monax materiam possit materiari?" |
"--Steve Wampler"
) @ {
# the following if expression has nearly the
# same effect as this expression
# (((/t_activated[C := t_ce[choose( )]],@C,C)|C)\1)
if /t_activated[C := t_ce[choose( )]]
then (@C,C)
else C
}
@ &main
}
# activate the producer first
@t_ce["producer"]
t_ce["producer"] := ^t_ce["producer"]
t_ce["consumer"] := ^t_ce["consumer"]
# activate a consumer first
@t_ce["consumer"]
end
procedure choose( )
return ["consumer"|"remusnoc"][?2]
end
# vim: set ai ts=2 sw=2
-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group