Boost logo

Boost :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2006-10-06 11:48:15

Anthony Williams wrote:
> Roland Schwarz <roland.schwarz_at_[hidden]> writes:
>> But I think your intent is: since we make the object appear like
>> they are static, they should behave similar to real static objects.
>> Correct?
> Yes, that's what I meant.

Umm, than as I would say in germanish "we get into devils kitchen".

1) We will need to assume that the call to atexit is thread safe
2) We will need to be able to have the compiler somehow generate
    a distinct function for every separate instance. And this
    only when the declaration has been done with the static keyword
    in front, else we would need to destroy when the object gets
    out of focus.

And even if we could manage this, the whole concept of destruction
order of static objects seems void in the presence of threads
anyways. You can see this e.g. from the fact that local static is
an illegal construct when seen from the perspective of the standard.
Even when protected by a mutex the destruction order is arbitrary
anyways, so I tend to say that even such a usage is very problematic.
(Put aside the question whether atexit calls are thread safe.)

So as I see it the only way out is to treat them as as heap objects
with dynamic lifetime (as what they really are) and their own rules,
of existence, while giving them certain properties that make them
usable as if they were static.

Call them lazy_static<> perhaps, or to make their dynamic nature
more visible to the user: lazy_ptr<> ?


Boost list run by bdawes at, gregod at, cpdaniel at, john at