[dmd-concurrency] real

Andrei Alexandrescu andrei at erdani.com
Thu Jan 28 16:43:53 PST 2010


Walter Bright wrote:
> You say the 2 word atomics lead to an entirely different design than 
> 1 word atomics. I agree and think that is pretty clear.

In fact it's pretty darn subtle. It took the academic community years to
figure that out. For a while it was believed that e.g. CAS2 was strictly
more powerful than CAS. It turned out it's just as powerful, just more
convenient.

> My point was that in trying to make 16 <=> 32 bit portability, the
> problems with allocating 100,000 byte arrays led one inevitably to
> using entirely different designs between the two, even if the
> language tried to make such code portable. You couldn't hide those
> design changes behind a simple macro.

I agree that having a larger space also enables different designs. That 
doesn't make machine-dependent designs a good thing!

> But very few people advocated forcing 32 bit designs to be coded as 
> if they were 16 bit ones. Similarly, I can't see disabling support 
> for 128 bit atomics just because they don't work on some CPUs.

We could and should allow machine-specific support via intrinsics that 
may or may not be available, not by enabling or disabling assignments!

Let me clarify what the most dangerous situation is.

1. A developer develops on a certain machine with good capabilities.

2. As we all know software design is like a gas - it will fill 
everything it can, so sooner or later the programmer writes a shared 
array assignment. She may not remember it's a dicey feature, or she may 
use it without realizing it (e.g. by calling a function against a shared 
array).

3. Now the code will only compile on a subset of platforms. This has two 
problematic consequences.

3a. There was no way during development to turn on a flag saying 
"Portability issues are errors".

3b. Rewriting is much more costly now that the entire program has been 
already designed to take advantage of the shaky functionality.

This _is_ a problem, and please - parallels with 16 bit etc. do not 
hold. Let's talk about the durned CAS2!

> The user does have a choice

NO! That is a false choice! Nonportabilities that go undetected until 
you port are NOT a choice, they are a problem with the language.

> - he can program it using 32 bit 
> constraints, and it will work successfully on 64 bit machines.

If you want this to be remotely palatable, you must define a flag that 
enforces portability. Can we negotiate something in that direction?


Andrei


More information about the dmd-concurrency mailing list