__PPS__ wrote:
[color=blue]
> Bool is not enough ( ++ operator is not atomic etc...),[/color]
What do you mean with the above.
[color=blue]
> there is no
> way you can garantie something to be locked using only language
> facilities - you should use mechanisms provided by the os.
> As an example, your bool variable before being changed/read may sit in
> a cpu register or cash memory. For multiprocessor machines you never
> know what happens with this bools as they may simultaneously sit in
> another processor's register/memory (processor that executes a
> concurrent thread)[/color]
Now you have placed me in thoughts. Under .NET, in a producer/consumer
relationship a common practice is to have a boolean value indicating
whether a new value has been produced or not.
For example, assuming
bool consumed=true;
A producer thread checks if this boolean is true and if yes, it assigns
a new value to the corresponding location and makes consumed=false;,
otherwise it enters the WaitSleepJoin state via a call to Monitor::Wait().
A consumer thread checks if this value is false, and if it is, it reads
the corresponding location and makes consumed=true; otherwise it enters
the WaitSleepJoin state.
This is the same variable (the data member of an object). How can it be
in the registers of two separate processors with different values each?
It doesn't sound possible.
--
Ioannis Vranos
http://www23.brinkster.com/noicys