Compiler reordering around mutex boundaries?

前端 未结 6 832
心在旅途
心在旅途 2020-12-17 23:14

Suppose I have my own non-inline functions LockMutex and UnlockMutex, which are using some proper mutex - such as boost - inside. How will the compiler know not to reorder o

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 23:30

    If the compiler can't guarantee that the function calls won't have side effects that will modify the variables between the calls, it can't move the code. If the variable is a local variable and you've never taken a reference or created a pointer to it, the compiler might assume it's safe to move; I don't know.

提交回复
热议问题