On Wednesday 11 September 2002 5:00 am, Art Eschenlauer wrote:
> I have the following pair of files; master loads slave and activates it.
> Without the break in the slave.icn file, it doesn't stop. I cannot
> understand why, when response() fails, slave does not stop unless I include
> the "break". The last thing written is:
> "master response - normal termination" and then it "hangs".
> Any insight would be most welcome; I'm stumped.
>
>
>
> # master.icn
> procedure main()
> local Cfunction, Cresponse, T
> T := table()
> @( Cfunction := create response() )
> @( Cresponse := load("slave",[Cfunction],&input,&output,&errout) )
> write( "master main - normal termination" )
> end
>
> procedure response()
> local Tout, Tin, s
> Tin := @&source
> every s := "hello" | "hello" | "invalid" | "stop" | "stop" do {
> Tout := table()
> Tout["command"] := s
> Tin := Tout@&source
> Tin["response"]=="OK" & every writes( !Tin["strings"] || " " )
> write( "response = " || Tin["response"] )
> }
> write("master response - normal termination")
> fail
> end
>
>
>
>
> # slave.icn
> procedure main(argv)
> local C, T
> C := argv[1]
> type(C)=="co-expression" | {
> ("this program must be loaded with the load procedure, \n"||
> "not run from the command line")@&source
> fail
> }
> T := table()
> T["response"] := "OK"
> while (T := T@C) do {
> write("command = "||T["command"])
> case T["command"] of {
> "stop": break stop("slave makes his exit")
> "hello": {
> T["response"] := "OK"
> T["strings"] := ["hello","world"]
> }
> default: T["response"] := "FAIL"
> }
> }
> end
>
>
>
>
>
> -------------------------------------------------------
> In remembrance
> www.osdn.com/911/
> _______________________________________________
> Unicon-group mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/unicon-group
I had trouble understanding your program, so I cut it down to the simplest
possible form, and I ended up with this :-
global A,B
procedure main()
A := create a()
B := create b()
@B
end
procedure a()
@B
end
procedure b()
@A
end
When run, this has the same behaviour as your original (without the
break/stop), namely it goes into an infinite loop. After a while I
understood why, and it is because when the co-expression fails at the end of
the procedure it tries to go restart &source. But that is never &main, so
the main procedure never finishes.
This is what happens:
@B calls b()
now &source is &main
b() invokes @A
@A calls a()
now &source is B
a() invokes @B again
B resumes where it left off, ie just after @A BUT
now &source is A
b() fails, so go resume &source, ie A
A resumes where it left off, ie just after @B
now &source is B
a() fails, so resume &source, ie B
B immediately fails so resume A
A immediately fails so resume B
etc ad infinitum
You can see this happening if you turn tracing on.
Kind regards,
R
-------------------------------------------------------
In remembrance
www.osdn.com/911/
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group