Here the code of "mt90.rex", changes (compared to "mt03.rex") in bold:
say "--->" .context~name
trace r
t=.Test~new
t~m1
t~m2
t~block-- wait for both methods to complete
*t**~**send(**"M1"**)****t**~**send(**"M2"**)****t**~**block **-- wait for both methods to complete
**t**~**start(**"M1"**)****t**~**start(**"M2"**)****t**~**block **-- wait for both methods to
complete *::class Test-- a test class ::attribute counter-- an attribute/an object variable ::method init-- constructor
expose counter-- must be very first statement trace a
say "arrived in:" .context~name
counter=0 ::method m1-- guarded method expose counter-- must be very
first statement trace a
counter+=1 -- increase counter say "arrived in:" .context~name"before
reply" call syssleep getSleepTime()-- randomly sleep reply tsk=1 -- to show up in trace call
syssleep getSleepTime()-- randomly sleep tsk=2 -- to show up in trace ::method m2unguarded --
unguarded method trace a
say "arrived in:" .context~name"before reply" call syssleep getSleepTime()--
randomly sleep reply call syssleep getSleepTime()-- randomly sleep self~counter=self~counter-1 --
decrease counter ::method block-- block caller, if counter<>0 expose counter-- must be very first
statement guard on when counter=0 -- attribute used as control variable return 99 ::routine getSleepTime
t=random(1,10)
return t/1000
Trace output without thread number:
---> G:\tmp\orx\multithreading\mt90.rex
3 *-* t=.Test~new
21 *-* say "arrived in:" .context~name
arrived in: INIT
22 *-* counter=0
>>> "a TEST"
4 *-* t~m1
27 *-* counter+=1 -- increase counter
28 *-* say "arrived in:" .context~name "before reply"
arrived in: M1 before reply
29 *-* call syssleep getSleepTime() -- randomly sleep
30 *-* reply
5 *-* t~m2
37 *-* say "arrived in:" .context~name "before reply"
arrived in: M2 before reply
>I> Method "M1" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
38 *-* call syssleep getSleepTime() -- randomly sleep
31 *-* tsk=1 -- to show up in trace
32 *-* call syssleep getSleepTime() -- randomly sleep
33 *-* tsk=2 -- to show up in trace
39 *-* reply
6 *-* t~block -- wait for both methods to complete
>I> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
40 *-* call syssleep getSleepTime() -- randomly sleep
41 *-* self~counter=self~counter-1 -- decrease counter
>>> "99"
7 *-* t~send("M1")
27 *-* counter+=1 -- increase counter
28 *-* say "arrived in:" .context~name "before reply"
arrived in: M1 before reply
29 *-* call syssleep getSleepTime() -- randomly sleep
30 *-* reply
8 *-* t~send("M2")
37 *-* say "arrived in:" .context~name "before reply"
arrived in: M2 before reply
31 *-* tsk=1 -- to show up in trace
32 *-* call syssleep getSleepTime() -- randomly sleep
38 *-* call syssleep getSleepTime() -- randomly sleep
39 *-* reply
33 *-* tsk=2 -- to show up in trace
9 *-* t~block -- wait for both methods to complete
>I> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
40 *-* call syssleep getSleepTime() -- randomly sleep
41 *-* self~counter=self~counter-1 -- decrease counter
>>> "99"
10 *-* t~start("M1")
>>> "a Message"
27 *-* counter+=1 -- increase counter
11 *-* t~start("M2")
28 *-* say "arrived in:" .context~name "before reply"
arrived in: M1 before reply
>>> "a Message"
37 *-* say "arrived in:" .context~name "before reply"
arrived in: M2 before reply
29 *-* call syssleep getSleepTime() -- randomly sleep
12 *-* t~block -- wait for both methods to complete
38 *-* call syssleep getSleepTime() -- randomly sleep
30 *-* reply
39 *-* reply
>I> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
40 *-* call syssleep getSleepTime() -- randomly sleep
>I> Method "M1" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
31 *-* tsk=1 -- to show up in trace
32 *-* call syssleep getSleepTime() -- randomly sleep
41 *-* self~counter=self~counter-1 -- decrease counter
33 *-* tsk=2 -- to show up in trace
>>> "99"
Trace ouput with thread number:
---> G:\tmp\orx\multithreading\mt90.rex
3 *- 1* t=.Test~new
21 *- 1* say "arrived in:" .context~name
arrived in: INIT
22 *- 1* counter=0
>> 1> "a TEST"
4 *- 1* t~m1
27 *- 1* counter+=1 -- increase counter
28 *- 1* say "arrived in:" .context~name "before reply"
arrived in: M1 before reply
29 *- 1* call syssleep getSleepTime() -- randomly sleep
30 *- 1* reply
5 *- 1* t~m2
37 *- 1* say "arrived in:" .context~name "before reply"
arrived in: M2 before reply
>I 2> Method "M1" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
38 *- 1* call syssleep getSleepTime() -- randomly sleep
31 *- 2* tsk=1 -- to show up in trace
32 *- 2* call syssleep getSleepTime() -- randomly sleep
33 *- 2* tsk=2 -- to show up in trace
39 *- 1* reply
6 *- 1* t~block -- wait for both methods to complete
>I 2> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
40 *- 2* call syssleep getSleepTime() -- randomly sleep
41 *- 2* self~counter=self~counter-1 -- decrease counter
>> 1> "99"
7 *- 1* t~send("M1")
27 *- 1* counter+=1 -- increase counter
28 *- 1* say "arrived in:" .context~name "before reply"
arrived in: M1 before reply
29 *- 1* call syssleep getSleepTime() -- randomly sleep
30 *- 1* reply
8 *- 1* t~send("M2")
37 *- 1* say "arrived in:" .context~name "before reply"
arrived in: M2 before reply
31 *- 2* tsk=1 -- to show up in trace
32 *- 2* call syssleep getSleepTime() -- randomly sleep
38 *- 1* call syssleep getSleepTime() -- randomly sleep
39 *- 1* reply
33 *- 2* tsk=2 -- to show up in trace
9 *- 1* t~block -- wait for both methods to complete
>I 3> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
40 *- 3* call syssleep getSleepTime() -- randomly sleep
41 *- 3* self~counter=self~counter-1 -- decrease counter
>> 1> "99"
10 *- 1* t~start("M1")
>> 1> "a Message"
27 *- 2* counter+=1 -- increase counter
11 *- 1* t~start("M2")
28 *- 2* say "arrived in:" .context~name "before reply"
arrived in: M1 before reply
>> 1> "a Message"
37 *- 3* say "arrived in:" .context~name "before reply"
arrived in: M2 before reply
29 *- 2* call syssleep getSleepTime() -- randomly sleep
12 *- 1* t~block -- wait for both methods to complete
38 *- 3* call syssleep getSleepTime() -- randomly sleep
30 *- 2* reply
39 *- 3* reply
>I 2> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
40 *- 2* call syssleep getSleepTime() -- randomly sleep
>I 4> Method "M1" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
31 *- 4* tsk=1 -- to show up in trace
32 *- 4* call syssleep getSleepTime() -- randomly sleep
41 *- 2* self~counter=self~counter-1 -- decrease counter
33 *- 4* tsk=2 -- to show up in trace
>> 1> "99"
Remark: despite the thread number it is extremely cumbersome to identify and distinguish the
different activities in the above output.
Multithreading trace output activated:
---> G:\tmp\orx\multithreading\mt90.rex
R1 T1 A1 3 *-* t=.Test~new
R1 T1 A2 V1 1* 21 *-* say "arrived in:" .context~name
arrived in: INIT
R1 T1 A2 V1 1* 22 *-* counter=0
R1 T1 A1 >>> "a TEST"
R1 T1 A1 4 *-* t~m1
R1 T1 A3 V1 1* 27 *-* counter+=1 -- increase counter
R1 T1 A3 V1 1* 28 *-* say "arrived in:" .context~name "before
reply"
arrived in: M1 before reply
R1 T1 A3 V1 1* 29 *-* call syssleep getSleepTime() --
randomly sleep
R1 T1 A3 V1 1* 30 *-* reply
R1 T1 A1 5 *-* t~m2
R1 T1 A4 V1 1 37 *-* say "arrived in:" .context~name "before
reply"
arrived in: M2 before reply
R1 T2 A3 V1 1* >I> Method "M1" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
R1 T1 A4 V1 1 38 *-* call syssleep getSleepTime() --
randomly sleep
R1 T2 A3 V1 1* 31 *-* tsk=1 -- to show up in
trace
R1 T2 A3 V1 1* 32 *-* call syssleep getSleepTime() --
randomly sleep
R1 T2 A3 V1 1* 33 *-* tsk=2 -- to show up in
trace
R1 T1 A4 V1 1 39 *-* reply
R1 T1 A1 6 *-* t~block -- wait for both
methods to complete
R1 T2 A4 V1 >I> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
R1 T2 A4 V1 40 *-* call syssleep getSleepTime() --
randomly sleep
R1 T2 A4 V1 41 *-* self~counter=self~counter-1 --
decrease counter
R1 T1 A1 >>> "99"
R1 T1 A1 7 *-* t~send("M1")
R1 T1 A5 V1 1* 27 *-* counter+=1 -- increase counter
R1 T1 A5 V1 1* 28 *-* say "arrived in:" .context~name "before
reply"
arrived in: M1 before reply
R1 T1 A5 V1 1* 29 *-* call syssleep getSleepTime() --
randomly sleep
R1 T1 A5 V1 1* 30 *-* reply
R1 T1 A1 8 *-* t~send("M2")
R1 T1 A6 V1 1 37 *-* say "arrived in:" .context~name "before
reply"
arrived in: M2 before reply
R1 T2 A5 V1 1* 31 *-* tsk=1 -- to show up in
trace
R1 T2 A5 V1 1* 32 *-* call syssleep getSleepTime() --
randomly sleep
R1 T1 A6 V1 1 38 *-* call syssleep getSleepTime() --
randomly sleep
R1 T1 A6 V1 1 39 *-* reply
R1 T2 A5 V1 1* 33 *-* tsk=2 -- to show up in
trace
R1 T1 A1 9 *-* t~block -- wait for both
methods to complete
R1 T3 A6 V1 >I> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
R1 T3 A6 V1 40 *-* call syssleep getSleepTime() --
randomly sleep
R1 T3 A6 V1 41 *-* self~counter=self~counter-1 --
decrease counter
R1 T1 A1 >>> "99"
R1 T1 A1 10 *-* t~start("M1")
R1 T1 A1 >>> "a Message"
R1 T2 A7 V1 1* 27 *-* counter+=1 -- increase counter
R1 T1 A1 11 *-* t~start("M2")
R1 T2 A7 V1 1* 28 *-* say "arrived in:" .context~name "before
reply"
arrived in: M1 before reply
R1 T1 A1 >>> "a Message"
R1 T3 A8 V1 1 37 *-* say "arrived in:" .context~name "before
reply"
arrived in: M2 before reply
R1 T2 A7 V1 1* 29 *-* call syssleep getSleepTime() --
randomly sleep
R1 T1 A1 12 *-* t~block -- wait for both
methods to complete
R1 T3 A8 V1 1 38 *-* call syssleep getSleepTime() --
randomly sleep
R1 T2 A7 V1 1* 30 *-* reply
R1 T3 A8 V1 1 39 *-* reply
R1 T2 A8 V1 1 >I> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
R1 T2 A8 V1 1 40 *-* call syssleep getSleepTime() --
randomly sleep
R1 T4 A7 V1 1* >I> Method "M1" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt90.rex".
R1 T4 A7 V1 1* 31 *-* tsk=1 -- to show up in
trace
R1 T4 A7 V1 1* 32 *-* call syssleep getSleepTime() --
randomly sleep
R1 T2 A8 V1 1 41 *-* self~counter=self~counter-1 --
decrease counter
R1 T4 A7 V1 1* 33 *-* tsk=2 -- to show up in
trace
R1 T1 A1 >>> "99"
Remark: it is fairly easy to identify and distinguish the different activities (and see how they get
interleaved with other activities).
---rony
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel