stdio performance in tango, stdlib, and perl
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Sat Mar 24 19:30:47 PDT 2007
Walter Bright wrote:
> Sean Kelly wrote:
>> There really isn't any way to do automatic locking with chained opCall
>> barring the use of proxy objects or something equally nasty. Also, it
>> hurts efficiency to always lock regardless of whether the user is
>> performing IO in multiple threads. The preferred method here is:
>>
>> synchronized( Cout )
>> Cout( a )( b )( c )();
>
> The trouble with that design is people working on subsystems or
> libraries, which will be combined by others into a working whole. Since
> it is extra work to add the synchronized statement, odds are pretty good
> it won't happen. Then, the whole gets erratic multithreading performance.
>
> Ideally, things should be inverted so that thread safety is the default
> behavior, and the extra-efficiency-dammit-I-know-what-I'm-doing is the
> extra work.
>
> One way to solve this problem is to use variadic templates as outlined
> in http://www.digitalmars.com/d/variadic-function-templates.html
>
> Back in the early days of Windows NT, when multithreaded programming was
> introduced to a mass platform, C compilers typically shipped with two
> runtime libraries - a single threaded one "for efficiency", and a
> multithreaded one. Also, to do multithreaded code, one had to predefine
> _MT or throw a command line switch. Inevitably, this was overlooked, and
> endless bugs consumed endless time. I made the decision early on to only
> ship threadsafe libraries, and have _MT always on. I've never regretted
> it, I'm sure it saved me a lot of tech support time, and avoided the
> perception that the compiler didn't work with multithreading.
MS does the same now if I remember correctly: all of its libraries are
MT by default.
I agree with Walter's sentiment that Cout(a)(b) is a design mistake.
Fortunately, now we have compile-time variadic functions, which will
make it easy to correct the design - Cout(a, b) can be made just as good
without having to chase typeinfo's at runtime.
Andrei
More information about the Digitalmars-d
mailing list