Here the code of "mt03.rex", changes (compared to "mt02.rex") in bold:
say "--->" .context~name
trace r
t=.Test~new
*t**~**start(**"M1"**) **-- send message on separate thread
**t**~**start(**"M2"**) **-- send message on separate thread* t~block-- wait for both
methods to complete, -- same as: t~send('BLOCK') ::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\mt03.rex
3 *-* t=.Test~new
15 *-* say "arrived in:" .context~name
arrived in: INIT
16 *-* counter=0
>>> "a TEST"
4 *-* t~start("M1") -- send message on separate thread
>>> "a Message"
21 *-* counter+=1 -- increase counter
5 *-* t~start("M2") -- send message on separate thread
22 *-* say "arrived in:" .context~name "before reply"
arrived in: M1 before reply
>>> "a Message"
31 *-* say "arrived in:" .context~name "before reply"
arrived in: M2 before reply
23 *-* call syssleep getSleepTime() -- randomly sleep
6 *-* t~block -- wait for both methods to complete,
32 *-* call syssleep getSleepTime() -- randomly sleep
33 *-* reply
>I> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt03.rex".
34 *-* call syssleep getSleepTime() -- randomly sleep
24 *-* reply
35 *-* self~counter=self~counter-1 -- decrease counter
>I> Method "M1" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt03.rex".
25 *-* tsk=1 -- to show up in trace
26 *-* call syssleep getSleepTime() -- randomly sleep
27 *-* tsk=2 -- to show up in trace
>>> "99"
Trace ouput with thread number:
---> G:\tmp\orx\multithreading\mt03.rex
3 *- 1* t=.Test~new
15 *- 1* say "arrived in:" .context~name
arrived in: INIT
16 *- 1* counter=0
>> 1> "a TEST"
4 *- 1* t~start("M1") -- send message on separate thread
>> 1> "a Message"
21 *- 2* counter+=1 -- increase counter
5 *- 1* t~start("M2") -- send message on separate thread
22 *- 2* say "arrived in:" .context~name "before reply"
arrived in: M1 before reply
>> 1> "a Message"
31 *- 3* say "arrived in:" .context~name "before reply"
arrived in: M2 before reply
23 *- 2* call syssleep getSleepTime() -- randomly sleep
6 *- 1* t~block -- wait for both methods to complete,
32 *- 3* call syssleep getSleepTime() -- randomly sleep
33 *- 3* reply
>I 4> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt03.rex".
34 *- 4* call syssleep getSleepTime() -- randomly sleep
24 *- 2* reply
35 *- 4* self~counter=self~counter-1 -- decrease counter
>I 3> Method "M1" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt03.rex".
25 *- 3* tsk=1 -- to show up in trace
26 *- 3* call syssleep getSleepTime() -- randomly sleep
27 *- 3* 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\mt03.rex
R1 T1 A1 3 *-* t=.Test~new
R1 T1 A2 V1 1* 15 *-* say "arrived in:" .context~name
arrived in: INIT
R1 T1 A2 V1 1* 16 *-* counter=0
R1 T1 A1 >>> "a TEST"
R1 T1 A1 4 *-* t~start("M1") -- send message
on separate thread
R1 T1 A1 >>> "a Message"
R1 T2 A3 V1 1* 21 *-* counter+=1 -- increase counter
R1 T1 A1 5 *-* t~start("M2") -- send message
on separate thread
R1 T2 A3 V1 1* 22 *-* say "arrived in:" .context~name "before reply"
arrived in: M1 before reply
R1 T1 A1 >>> "a Message"
R1 T3 A4 V1 1 31 *-* say "arrived in:" .context~name "before
reply"
arrived in: M2 before reply
R1 T2 A3 V1 1* 23 *-* call syssleep getSleepTime() -- randomly sleep
R1 T1 A1 6 *-* t~block -- wait for both
methods to complete,
R1 T3 A4 V1 1 32 *-* call syssleep getSleepTime() --
randomly sleep
R1 T3 A4 V1 1 33 *-* reply
R1 T4 A4 V1 1 >I> Method "M2" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt03.rex".
R1 T4 A4 V1 1 34 *-* call syssleep getSleepTime() --
randomly sleep
R1 T2 A3 V1 1* 24 *-* reply
R1 T4 A4 V1 1 35 *-* self~counter=self~counter-1 --
decrease counter
R1 T3 A3 V1 1* >I> Method "M1" with scope "TEST" in package
"G:\tmp\orx\multithreading\mt03.rex". R1 T3 A3 V1 1* 25 *-* tsk=1 -- to show
up in trace R1 T3
A3 V1 1* 26 *-* call syssleep getSleepTime() -- randomly sleep R1 T3 A3 V1
1* 27 *-* 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), activity A3 is just highlighted as an example.
---rony
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel