WordCount performance
Sean Kelly
sean at invisibleduck.org
Fri Mar 28 17:26:13 PDT 2008
== Quote from Walter Bright (newshound1 at digitalmars.com)'s article
> Sean Kelly wrote:
> > Another option might be to check the thread count is greater than
> > 1 and only lock if it is. Tango has a routine called thread_needLock
> > for this purpose, though it goes a bit farther and is true once a
> > thread has been created through program termination. This avoids
> > problems with the situation where you have multiple threads running
> > and all but one terminate but memory is not yet synchronized.
> You have to be very careful with such schemes because they can run afoul
> of the notoriously difficult to comprehend "double checked locking" bug.
With the way this call is implemented in Tango, it is completely safe to omit
a mutex lock on a false return so long as the ostensibly locked code does
not call into code that may create a thread. For something like an IO
operation, this seems pretty unlikely so it's a reasonable optimization, if
perhaps progressively less useful as multithreading becomes more common.
Sean
More information about the Digitalmars-d
mailing list