Process Scheduling/Threads

Tim Rowledge tim at sumeru.stanford.edu
Wed Apr 13 17:00:46 UTC 2005


Daniel Salama <dsalama at user.net> wrote:

> I ran the following:
> 
> queue := SharedQueue new.
> [10000 timesRepeat: [queue nextPut: 1]] fork.
> [10000 timesRepeat: [queue nextPut: 2]] fork.
> queue inspect.
> 
> and when I inspected "queue", it shows all 1s and then all 2s. If I'm 
> forking these two processes, shouldn't they run concurrently? I should 
> be able to see 1s and 2s mixed up.
Nope, what the code does is make a process adding '1's and then another adding '2's. Process 1 will run until it is interrupted - which will be until it finishes in many cases as it will run pretty quickly. If something interrupts it, then it gets put on the back of the queue for that priority and process 2 (or the next, if something else got there first) will go.

Try 
|queue| 
queue := SharedQueue new.
 [10000 timesRepeat: [queue nextPut: 1. Processor yield]] fork.
 [10000 timesRepeat: [queue nextPut: 2. Processor yield]] fork.
 queue inspect.
instead as an example.

tim
--
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
Variables won't; constants aren't.  - Osborn



More information about the Squeak-dev mailing list