digitalmars.D - RefCounted no thread-safety?
- Kira Backes (9/9) Jan 12 2014 Hello,
- Dmitry Olshansky (5/13) Jan 12 2014 It cannot. In D everything is thread-local by default.
- Michel Fortin (8/18) Jan 12 2014 There's still a race when RefCounted is located in a GC-allocated
- Dmitry Olshansky (6/21) Jan 12 2014 Awful.
- Kira Backes (5/7) Jan 12 2014 Hello, thanks for the info, I did not test compiling with shared.
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. Is this correct or am I overlooking something (I’m still new to D). If it is correct then this should either be fixed or if it is intentional it should really be documented. rgds, Kira
Jan 12 2014
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.Is this correct or am I overlooking something (I’m still new to D). If it is correct then this should either be fixed or if it is intentional it should really be documented.-- Dmitry Olshansky
Jan 12 2014
On 2014-01-12 20:08:17 +0000, Dmitry Olshansky <dmitry.olsh gmail.com> said:12-Jan-2014 23:59, Kira Backes пишет: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 michelf.ca http://michelf.caHello, 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.
Jan 12 2014
13-Jan-2014 00:12, Michel Fortin пишет:On 2014-01-12 20:08:17 +0000, Dmitry Olshansky <dmitry.olsh gmail.com> said:Awful. The only thing worse is that arrays of structs don't have their destructors called at all. -- Dmitry Olshansky12-Jan-2014 23:59, Kira Backes пишет: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=4624Hello, 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.
Jan 12 2014
On Sunday, 12 January 2014 at 20:08:25 UTC, Dmitry Olshansky wrote:It cannot. In D everything is thread-local by default. And shared(RefCounted!T) would most likely fail to compile.Hello, thanks for the info, I did not test compiling with shared. You’re right about this, I was just too much used to C++11’s shared_ptr I think ;-)
Jan 12 2014