RefCounted no thread-safety?

Michel Fortin michel.fortin at michelf.ca
Sun Jan 12 12:12:48 PST 2014


On 2014-01-12 20:08:17 +0000, Dmitry Olshansky <dmitry.olsh at gmail.com> said:

> 12-Jan-2014 23:59, Kira Backes пишет:
>> Hello,
>> 
>> 
>> I was just looking at the source of std.typecons.RefCounted and it seems
>> like it is not thread-safe at all, the count variable may be written
>> concurrently from several threads which could cause data corruption.
> 
> It cannot. In D everything is thread-local by default.
> And  shared(RefCounted!T) would most likely fail to compile.

There's still a race when RefCounted is located in a GC-allocated 
memory block, as the destructor might get called from any thread.
https://d.puremagic.com/issues/show_bug.cgi?id=4624

-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca



More information about the Digitalmars-d mailing list