Looking for Monitor example

Chris Muller chris at funkyobjects.org
Sat Mar 18 20:08:13 UTC 2006


Has anyone used the heavyweight (Mesa) Monitor?  I want to try the conditional waiting, but keep getting a 'Monitor access violation'.  I think its actually a bug in the code; its signaling code is performing #checkOwnerProcess, but this should only be done by the 'wait' code (which it is).
 
 The disconcerting part of this is; I don't see how Monitor can work at all this way.  There is no test case in the 3.8 image and I've found no example usages which could help prove me wrong.
 
 I wrote a test case demonstrating how I think it can be used.  Running the test results in a Monitor access violation.  But if I remove the call to #checkOwnerProcess in the signal method (my proposed fix) the test works fine.
 
 So, does anyone have any experience with the heavyweight (Mesa) Monitor and how did it work for you?  Does this test represent misuse or is there really an issue with Monitor?
 
 testConditionalWaits
     "Start two background processes that build an OrderedCollection with the numbers 1 to 1000.  The 'fives' process will only add numbers modulo 5 = 0 (i.e., 5, 10, 15, 20, ...) whereas the 'nonFives' process adds all the others.  A third monitor waits until the goal is reached before asserting the goal was reached successfully."
     | goal work fives nonFives counter goalReached goalMonitor |
     goal _ (1 to: 1000) asOrderedCollection.
     work _ OrderedCollection new.
     fives _ Monitor new.
     nonFives _ Monitor new.
     counter _ 0.
     goalReached _ false.
     goalMonitor _ Monitor new.
     [ fives critical:
         [ [ fives waitUntil: [ counter \\ 5 = 0 ].
         goalReached or:
             [ work add: (counter _ counter+1).
             nonFives signal.
             goalReached _ counter >= goal size ] ] whileFalse.
         goalMonitor signal ] ] fork.
     [ nonFives critical:
         [ [ nonFives waitWhile: [ counter \\ 5 = 0 ].
         goalReached or:
             [ work add: (counter _ counter+1).
             fives signal.
             goalReached _ counter >= goal size ] ] whileFalse.
         goalMonitor signal ] ] fork.
     goalMonitor critical:
         [ goalMonitor waitUntil: [ goalReached ].
         self assert: goal = work ]
 
 Thanks..
 




More information about the Squeak-dev mailing list