Squeak process implicitly yields?

Masashi Umezawa umejava at mars.dti.ne.jp
Mon Apr 26 15:49:48 UTC 2004


Hi,

In my understanding, Smalltalk processes are non-preemptive if their
priorities are the same.

But when I tried this code in Squeak ("print it"),

---
aStream := WriteStream on: (String new: 200).
aSemaphore := Semaphore new.
aBlockClosure := [:argument | 0 to: 9
    do:
        [:n |
                 aStream nextPutAll: argument.
                 aStream nextPutAll: '('.
                 aStream nextPutAll: n printString.
                 aStream nextPutAll: ')'.
                 aStream nextPutAll: ' '.
                 1000 timesRepeat: [100 factorial].
                 ].
    aSemaphore signal].
aBlockClosure2 := [:argument2 | 0 to: 9
    do:
        [:n2 |
                 aStream nextPutAll: argument2.
                 aStream nextPutAll: '('.
                 aStream nextPutAll: n2 printString.
                 aStream nextPutAll: ')'.
                 aStream nextPutAll: ' '.
                 100 timesRepeat: [100 factorial].
                 ].
    aSemaphore signal].
aBlockClosure3 := [:argument3 | 0 to: 9
    do:
        [:n3 |
                 aStream nextPutAll: argument3.
                 aStream nextPutAll: '('.
                 aStream nextPutAll: n3 printString.
                 aStream nextPutAll: ')'.
                 aStream nextPutAll: ' '.
                 10 timesRepeat: [100 factorial].
                 ].
    aSemaphore signal].
aStream nextPutAll: 'Black'; nextPutAll: ' '.
[aBlockClosure value: 'Red'] fork.
[aBlockClosure2 value: 'Green'] fork.
[aBlockClosure3 value: 'Blue'] fork.
aStream nextPutAll: 'White'; nextPutAll: ' '.
3 timesRepeat: [aSemaphore wait].
aStream contents

---

The result was funny to me:

 'Black White Red(0) Red(1) Red(2) Green(0) Green(1) Green(2) Green(3)
  Green(4) Green(5) Green(6) Green(7) Green(8) Green(9) Blue(0) Blue(1)
  Blue(2) Blue(3) Blue(4) Blue(5) Blue(6) Blue(7) Blue(8) Blue(9) Red(3)
  Red(4) Red(5) Red(6) Red(7) Red(8) Red(9) '

(Change the 'xxx timesRepeat:' value. You can get various results).

Are there implicit yields in Squeak?

In, VW and Dolphin, I can get the expected results:

 'Black White Red(0) Red(1) Red(2) Red(3) Red(4) Red(5) Red(6) Red(7)
  Red(8) Red(9) Green(0) Green(1) Green(2) Green(3) Green(4) Green(5)
  Green(6) Green(7) Green(8) Green(9) Blue(0) Blue(1) Blue(2) Blue(3)
  Blue(4) Blue(5) Blue(6) Blue(7) Blue(8) Blue(9) '

I've tested it in Squeak 3.6 & 3.7b in Windows.

Cheers,
---
[:masashi | ^umezawa]




More information about the Squeak-dev mailing list