@safe: shared string s; void f() @safe { s="s"; } A slice is stored with two mov instructions, so when the global variable is modified concurrently, it can end up with pointer from one array and length from another.
This is more an issue with shared than with @safe. AFAIK @safe makes no guarantees when it comes to data races.
@safe exists to makes guarantees :) And memory safety and data races are not shared's issues.
(In reply to anonymous4 from comment #2) > @safe exists to makes guarantees :) > And memory safety and data races are not shared's issues. Data races are absolutely shared's problem. The issue is shared has never been fully implemented. See https://issues.dlang.org/show_bug.cgi?id=14932 The only place you can see what shared is supposed to be is in Andrei's book "The D Programming Language". @safe exists to ensure memory safety; data races do not fall under that umbrella.
If you corrupt memory in @safe code, then @safe fails, I think, this is specified pretty clearly, whether this happens due to sharing is unimportant. If shared should allow data races can be discussed in issue 14932.
If you compile with -preview=nosharedaccess than this code no longer compiles: "Error: direct access to shared `s` is not allowed, see `core.atomic`". Closing as WORKSFORME.