Block temps was: Porting from other dialects

Patrick Logan patrickl at servio.gemstone.com
Tue Aug 18 22:56:00 UTC 1998


Correction to my previous example (if anyone thinks this is a halway
reasonable idea, or if they have any reasons why it is not, please let
me know)...

================================================================

Original source...

  | output supposedlyReentrantBlock guard |
  output := WriteStream on: String new. "I'm used to String new writeStream..."
  guard := SharedQueue new.   "Used for process synchronization"
  supposedlyReentrantBlock := 
    [ :array  |  
     1 to: array size do: 
       [ :index | 
        output print: (array at: index); space. Processor yield. ].
     guard nextPut: nil.   "  signal the guard  "
    ].
  [supposedlyReentrantBlock value: #(1 2 3) ] fork.
  [supposedlyReentrantBlock value: #(-1 -2 -3) ] fork.
  guard next; next.  "  wait for two guard signalings  "
  ^output contents 

================================================================

Rewritten as...

  | output guard 
    supposedlyReentrantBlockOne supposedlyReentrantBlockTwo |
  output := WriteStream on: String new. "I'm used to String new writeStream..."
  guard := SharedQueue new.   "Used for process synchronization"
  [supposedlyReentrantBlockOne := 
     ClassForSupposedlyReentrantBlock guard: guard output: output.
   supposedlyReentrantBlockOne value: #(1 2 3)] fork.
  [supposedlyReentrantBlockTwo := 
     ClassForSupposedlyReentrantBlock guard: guard output: output.
   supposedlyReentrantBlockTwo value: #(-1 -2 -3)] fork.
  guard next; next.  "  wait for two guard signalings  "
  ^output contents

....where...

ClassForSupposedlyReentrantBlock class>>guard: guard output: output

  ^ClassForSupposedlyReentrantBlock new
    guard: guard output: output;
    yourself

ClassForSupposedlyReentrantBlock>>value: array

  1 to: array size do: 
    [ :index | 
     output print: (array at: index); space. Processor yield.].
  guard nextPut: nil.   "  signal the guard  "

================================================================

-- 
Patrick Logan                 mailto:patrickl at gemstone.com
Voice 503-533-3365            Fax   503-629-8556
Gemstone Systems, Inc         http://www.gemstone.com





More information about the Squeak-dev mailing list