3 ms·
This is an elegant solution to the double checked locking bug http://en.wikipedia.org/wiki/Double-checked_locking http://en.wikipedia.org/wiki/Double-checked_lo
by WalterBright 14y ago
This is an elegant solution to the double checked locking bug http://en.wikipedia.org/wiki/Double-checked_locking http://en.wikipedia.org/wiki/Double-checked_locking, incurring insignificant overhead.
- rbehrends 14y agoUnfortunately, the space overhead is not quite that insignificant. It requires at least one bit of storage per thread; this does not matter much for a singleton class, but if you want to implement more general write-once data structures (such as arrays or hash tables), it's not negligible. Somewhat less problematic is that fast TLS is not natively available on all architectures (in particular, Mac OS X). Luckily, this can be worked around relatively easily.
- WalterBright 14y agoD does its own TLS implementation on OS X. But now that newer versions of OS X have native TLS, we'll be scrapping ours and using the native one.