Is what constitutes a failed initialization of block-scope static or thread storage duration variables underspecified?

后端 未结 2 577
盖世英雄少女心
盖世英雄少女心 2021-02-15 23:56

After answering this question and not finding a satisfying answer in the standard paper, I started wondering. The standard states the following w.r.t. initialization of mentione

2条回答
  •  遥遥无期
    2021-02-16 00:32

    Just because the text mentions one particular case doesn't imply by omission that others would be any different. If there are other ways to prevent the initialization from completing, the implementation must retry at the next execution.

    I think Nicol's answer is mostly correct, but a non-trivial constructor does not imply a non-trivial destructor. longjmp may therefore interrupt initialization such that it must be retried. This is tricky only in a multithreaded environment, where a mutex is needed to prevent a race condition between threads vying to be the first to execute the initialization. The phantom mutex object needs a non-trivial destructor even if the initialized object does not have one. The likely result is deadlock. This is probably good material for a DR.

提交回复
热议问题