Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2002-07-20 21:02:33


Keith Burton wrote:

[snip]
>
> (3) why is there any need for thread-safety primitives ?
> All my experience tells me that putting 'thread safety' into classes
> at this level just generates an illusion of safety with an unnecessary

> overhead for every use.
>

O(1) complexity visitation can be guaranteed only (?) through a dispatch
table of some kind. That limits the options for how the dispatch table
object can be stored:

(1) Non-static member object.

This works, but it is inefficient as every instance of a particular
variant must create the table, which is the same for all variants of the
same type.

(2) Static member object.

This is problematic because it means a variant cannot be safely used in
other global static objects.

(3) Local static object.

Thread safety primitives are needed because the behavior of a local
static object is undefined in a multithreaded environment; accordingly,
thread-safety primitives are required so that access to the object is
serialized.

(See
http://www.cuj.com/articles/1999/9910/9910b/9910b.htm?topic=articles for
a short discussion of this problem in a different context.)

---
But, as Douglas Gregor noted, worrying about complexity guarantees for
variant visitation may be premature optimization.
So I guess cascading-if's (and O(N) complexity) are the way to go for
now. And maybe compiler optimizations will make the issue moot anyway.
Eric

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk