EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: c++ static initialization
From: Eric Norum <[email protected]>
To: Benjamin Franksen <[email protected]>
Cc: EPICS core-talk <[email protected]>
Date: Thu, 11 Aug 2011 12:44:02 -0700
On Aug 11, 2011, at 10:57 AM, Benjamin Franksen wrote:

> Hi Andrew
> 
> What I would try to avoid at all cost is non-trivial initialization in a
> *constructor* for a static object. I listed lazy initialization as one
> alternative possibility. Just to make sure we re talking about the same
> concept, what I mean is to add some code like
> 
>  if (!this->initialized) this->initialize();

That doesn't look thread-safe to me.  The initialize method could be invoked multiple times.

> 
> at the start of each method. I may be wrong but I can't think of any subsystem
> where this approach cannot be used instead of calling initialize() from a
> constructor. Remember, when all code in base was written in C we simply did
> not *have* the possibility to do anything non-trivial before main (or before
> the startup script starts to run); back then there existed exactly the two
> ways to solve the problem that I listed: lazy init, or explicit call to init
> during startup.
> 

-- 
Eric Norum
[email protected]






References:
c++ static initialization Jeff Hill
Re: c++ static initialization Benjamin Franksen
Re: c++ static initialization Andrew Johnson
Re: c++ static initialization Benjamin Franksen

Navigate by Date:
Prev: Re: c++ static initialization Benjamin Franksen
Next: Re: c++ static initialization Andrew Johnson
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: c++ static initialization Benjamin Franksen
Next: Re: c++ static initialization Andrew Johnson
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Feb 2012 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·