May volatile be in user defined types to help writing thread-safe code

前端 未结 8 2221
别那么骄傲
别那么骄傲 2020-12-04 18:19

I know, it has been made quite clear in a couple of questions/answers before, that volatile is related to the visible state of the c++ memory model and not to m

8条回答
  •  天命终不由人
    2020-12-04 18:53

    In the article the keyword is used more like a required_thread_safety tag than the actual intended use of volatile.

    Without having read the article – why isn’t Andrei using said required_thread_safety tag then? Abusing volatile doesn’t sound such a good idea here. I believe this causes more confusion (like you said), rather than avoiding it.

    That said, volatile may sometimes be required in multi-threaded code even if it’s not a sufficient condition, just to prevent the compiler from optimizing away checks that rely on asynchronous update of a value.

提交回复
热议问题