Why D is not popular enough?
ag0aep6g via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 12 14:41:53 PDT 2016
On 08/12/2016 09:41 PM, ag0aep6g wrote:
> So, `shared int x; x = x + 1;` is ok, as far as I see now. But with
> other types, unsafe reads/writes are generated.
Missing alignment can also throw the compiler off:
----
alias T = int;
enum T a = 0x01_01_01_01;
enum T b = 0x02_02_02_02;
struct S
{
byte[13] padding;
align(1) T x = a;
}
shared S s;
import core.thread: Thread;
void write()
{
bool flip = false;
foreach (i; 0 .. 1_000_000)
{
if (flip) s.x = a; else s.x = b;
flip = !flip;
}
}
void main()
{
auto t = new Thread(&write);
t.start();
foreach (i; 0 .. 1_000_000)
{
T r = s.x;
assert(r == a || r == b); // fails
}
t.join();
}
----
More information about the Digitalmars-d
mailing list