Read to stdout doesn't trigger correct action

Steven Schveighoffer schveiguy at gmail.com
Mon Jun 22 14:27:18 UTC 2020


On 6/22/20 10:05 AM, IGotD- wrote:

> This seems do some atomic operation preventing the D File class for 
> stdio not to be initialized several times. I'm not quite sure if this is 
> global or per thread but I guess it is for the entire process. For some 
> reason the std File classes are never initialized at all. Another 
> problem is that the function that is called to obtain the clib stdin/out 
> use a structure that is lazy initialized per thread, so it must be 
> called at least a first time for each thread in order to get the correct 
> stdin/out. Removing the atomic operations so that the File 
> initialization is done every time, then it works.

The point of the makeGlobal call is to avoid dependency on static ctors 
(which is how it was done before this implementation), to allow usage of 
stdio without druntime.

The __gshared designation is equivalent to C's globals, so it is shared 
among all threads (though the type is still as if it were thread-local).

> Question is if "File makeGlobal(StdFileHandle _iob)()" is correct when 
> it comes to ensure compatibility among all the clib versions out there. 
> Not too seldom are clib global variables really functions, like errno is 
> often a function rather than a variable. The internal code the the clib 
> (Newlib) does not have this "optimization" but always get stdin/out 
> using this function call.

I'm sure if there is a clib that doesn't work with this, it is a bug 
with druntime, and should be addressed. I don't know enough about the 
exact functionality to be able to write such a bug report, but you 
probably should if it's not working for you.

-Steve


More information about the Digitalmars-d-learn mailing list