Bug 10794 – Unsynchronized access to data of syncronized class

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-11T10:11:30Z
Last change time
2023-01-04T13:49:48Z
Assigned to
No Owner
Creator
Roman

Comments

Comment #0 by freeslave93 — 2013-08-11T10:11:30Z
Here is something similar to example from Alexandrescu's book (13.14.1 Temporary Protection == No Escape): import std.stdio; int* ptr; void sneaky(out int bar) { ptr = &bar; } synchronized class B { private int bar; public void foo() { sneaky(bar); } int getBar() { return bar; } void setBar(int b) { bar = b; } } void main() { auto b = new shared(B); b.setBar(5); b.foo(); *ptr = 6; writeln(*ptr); writeln(b.getBar()); } I just replaced 'ref' with 'out' and now it compiles fine. Is it suppose to work this way? I also wonder why we have to write 'new shared(NameOfClass)' when class is synchronized, although we can't create not shared instance of synchronized class. Was it designed to make code more explicit?
Comment #1 by razvan.nitu1305 — 2023-01-04T13:49:48Z
I cannot reproduce this. I am getting: test.d(15): Error: function `test.sneaky(out int bar)` is not callable using argument types `(shared(int))` test.d(15): cannot pass argument `this.bar` of type `shared(int)` to parameter `out int bar` Which is correct.