[squid-dev] [PATCH] tentative fix for bug 4438

Alex Rousskov rousskov at measurement-factory.com
Sun Mar 6 23:25:56 UTC 2016


On 03/06/2016 02:15 PM, Kinkie wrote:
> On Sun, Mar 6, 2016 at 9:41 PM, Alex Rousskov wrote:
>> On 03/06/2016 11:16 AM, Kinkie wrote:
> Having the MemBlob pools be static
> members of the MemBlob class will guarantee proper initialization
> before even the first MemBlob is instantiated, won't it?


AFAIK, no, it will not guarantee that: The location of a static object
inside or outside a class is pretty much irrelevant when it comes to the
initialization order of various globals. The initialization algorithm
does not know which code depends on which code. It just goes through all
non-constant non-local objects and creates them one by one, in
essentially random translation units order(*).

For example, given this class declaration in some header file:

  class MemBlob {
  public:
      static Pool Pool_;
      MemBlob(size_t sz) { buffer = Pool_.allocate(sz); }
      ...
  };


It is possible to use the above MemBlob before Pool_ is created because
the .cc file where MemBlob::Pool_ is defined may be processed after the
.cc file where MemBlob user code lives. Here is an example of such user
code in some other.cc file, defining a non-local global MemBlob:

  // will be created either before or after MemBlob::Pool_
  static MemBlob MyBlob(123);


Whether the above is related to Yuri's bug, I do not know.


HTH,

Alex.
(*) I am not being very precise here. Please consult C++ documents for
the exact details and correct terminology. The same documents will
detail other initialization stages not mentioned above.



More information about the squid-dev mailing list