boost::lock_guard vs boost::mutex::scoped_lock

后端 未结 2 667
渐次进展
渐次进展 2020-12-30 19:25

Which is preferred boost::lock_guard or boost::mutex::scoped_lock?

I\'m using Boost.Thread with the hope to move to C++11 threading when it

2条回答
  •  情深已故
    2020-12-30 20:04

    Amit is right: boost::mutex::scoped_lock is a typedef for boost::unique_lock, not lock_guard. scoped_lock is not available in C++0x.

    Unless you need the flexibility of unique_lock, I would use lock_guard. It is simpler, and more clearly expresses the intent to limit the lock to a defined scope.

提交回复
热议问题