== Quote from Benjamin Thaut ([email protected])'s article
> The following testcase (when executed on dual core at least) results in
> a endless loop inside atomicOp.
> import std.stdio;
> import std.concurrency;
> enum Messages {
>       GO,
>       END
> }
> shared class Account {
>       private double amount = 0;
>       double getAmount() const {
>               return amount;
>       }
>       void change(double change){
>               atomicOp!"+="(amount,change);
>       }
> }
> shared Account bank = null;
> void otherThread(Tid father){
>       send(father,Messages.GO);
>       for(int i=0;i<1000;i++)
>               bank.change(-100);
>       send(father,Messages.END);
> }
> void main(string[] args)
> {
>       bank = new Account();
>       spawn(&otherThread,thisTid);
>       receiveOnly!(Messages)();
>       for(int i=0;i<1000;i++)
>               bank.change(+100);
>       receiveOnly!(Messages)();
>       writefln("Program finished. Amount is %s",bank.getAmount());
> }
> Is this a bug, or am I doing something wrong here?
> If it is a bug it is kind of critical because people which are reading
> the "the D programming language" book won't be happy to find out that
> some of the given examples do not work yet.

http://d.puremagic.com/issues/show_bug.cgi?id=4782

Basically, atomicLoad (which atomicOp uses) always returns in ALU registers.
Floating point numbers need to be returned in floating point registers.
Therefore, a NaN always gets returned from atomicLoad!double, and a NaN isn't
equal to anything.

Reply via email to