[Issue 15768] std.stdio.trustedStdout accesses __gshared data without synchronization.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jul 28 07:22:40 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15768

--- Comment #7 from Jack Stouffer <jack at jackstouffer.com> ---
(In reply to Sobirari Muhomori from comment #6)
> (In reply to Jack Stouffer from comment #2)
> > In order for stdout, stdin, and stderr to be shared(File)
> 
> 1. shared(File) stdio will break code that consumes it as unshared

Yup, and I don't see a way around that. Apparently when std.stdio was designed,
shared still had bugs, so it wasn't used and __gshared was chosen instead. That
was a huge mistake that we are now paying for. shared is the right choice here;
this is specifically what shared was designed for.

OT: IMO anytime __gshared shows up in Phobos outside of C bindings, it's a bug.
I don't care if it's using locks, or the code is slightly slower, we need to
dog food shared if shared going to get any good.

> 2. always doing interlocked counting for shared(File) is still slow,
> consider this optimization: https://dpaste.dzfl.pl/d8dab5b7aa1f

You can further optimize with a new implementation by removing the ref count
from a non shared File instance.

--


More information about the Digitalmars-d-bugs mailing list