[squeak-dev] Re: Suspending process fix

Igor Stasenko siguctua at gmail.com
Tue Apr 28 05:22:37 UTC 2009


2009/4/28 Igor Stasenko <siguctua at gmail.com>:
[snip]
>
> If we suppose, that we are running in ideal environment, where
> processes are running in parallel, then nothing prevents us to
> implement waiting as following:
>
> Semaphore>>wait
> | flag |
>  flag := Array with: false with: nil.  "a second slot will be used
> for the 'next' pointer, for chaining the list of consumers who waiting
> on signal"
>
>  self scheduleFlagToSignal: flag.
>
>  [ flag at: 1 ] whileFalse: []
>
> it is clear, that to exit from loop, there should be external process
> who alters the flag from false to true.
> Also, it is clear, that suspending the loop in the middle can't affect
> other processes which possibly waiting for same semaphore signal, as
> well as it guarantees that semaphore signal will be consumed in
> correct order.
>
A small correction: is will work correctly even in preemptive
environment, except that it will waste the CPU cycles in loop when
waiting.

> This example illustrates the fundamental difference between waiting
> and suspending/preemption, while in Squeak, unfortunately there is an
> equal sign between them (semaphores use a VM's preemption mechanism to
> implement waiting).
> If we take this example as a base, then of course we can implement a
> correct scenario which deals with preemption and scheduling.
>
>

-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list