How to use lock_guard when returning protected data

前端 未结 3 855
半阙折子戏
半阙折子戏 2020-12-06 09:46

I have a question concerning the use of boost::lock_guard (or similar scoped locks) and using variables that should be protected by the lock in a return

3条回答
  •  孤街浪徒
    2020-12-06 10:27

    Just a straight return as in your first example is correct. The return value is constructed before the local variables are destroyed, and thus before the lock is released.

提交回复
热议问题