you asked for opinions, here is mine:
Am Dienstag, 9. August 2011, um 22:42:37 schrieb Jeff Hill:
> Ref: http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.14
> Of course C++ is really different from C in that some significant code can
> run during static initialization. The above FAQ mentions how to avoid some
> really serious issues. All of this is pretty common knowledge, but one has
> to be careful, and I have definitely seen this bug biting in EPICS base
(1) Static objects should be avoided wherever possible.
(2) If static objects are used, the constructor should be trivial, i.e. not
perform anything except setting members to default values.
(3) Non-trivial initialization for complex objects should be done in a regular
method either lazily ("Construct On First Use") or by an explicit call from
some startup routine. The latter has the advantage of a well-defined order of
initialization; the former is sometimes more convenient.
> However there is still a related issue which should be well understood; not
> everyone agrees if threads should be started during C++ static
> initialization or not.
(4) Starting threads inside static initialization is a bad idea and should not
be allowed (see rule 2).
> If multiple threads are running during c++ static
> initialization then the solution in the above FAQ doesn't apply and the
> only solution is epicsThreadOnce,
(5) epicsThreadOnce should also be avoided wherever possible. Using it means
objects cannot be freely passed between threads which is detriment to
Helmholtz-Zentrum Berlin für Materialien und Energie GmbH
Mitglied der Hermann von Helmholtz-Gemeinschaft Deutscher Forschungszentren e.V.
Aufsichtsrat: Vorsitzender Prof. Dr. Dr. h.c. mult. Joachim Treusch, stv. Vorsitzende Dr. Beatrix Vierkorn-Rudolph
Geschäftsführer: Prof. Dr. Anke Rita Kaysser-Pyzalla, Dr. Ulrich Breuer
Sitz Berlin, AG Charlottenburg, 89 HRB 5583
- Re: c++ static initialization Eric Norum
- Re: c++ static initialization Andrew Johnson
- c++ static initialization Jeff Hill
- Navigate by Date:
RE: c++ static initialization Jeff Hill
Re: c++ static initialization Hill, Bruce
- Navigate by Thread:
c++ static initialization Jeff Hill
Re: c++ static initialization Eric Norum