stdio performance in tango, stdlib, and perl
Walter Bright
newshound at digitalmars.com
Sat Mar 24 16:41:06 PDT 2007
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.
More information about the Digitalmars-d
mailing list