Thread-safe static variables without mutexing?

前端 未结 5 1193
无人及你
无人及你 2021-02-19 10:32

I remember reading that static variables declared inside methods is not thread-safe. (See What about the Meyer\'s singleton? as mentioned by Todd Gardner)

Dog* M         


        
5条回答
  •  孤独总比滥情好
    2021-02-19 10:58

    AFAIK, the only time this has been done safely and without mutexes or prior initialisation of global instances is in Matthew Wilson's Imperfect C++, which discusses how to do this using a "spin mutex". I'm not near to my copy of it, so can't tell you any more precisely at this time.

    IIRC, there are some examples of the use of this inside the STLSoft libraries, though I can't remember which components at this time.

提交回复
热议问题