有Boost的范围的互斥和WINAPI的关键部分之间的差异?
在Windows环境中,是一个使用WinAPI的的关键部分Boost的范围互斥体,还是其他什么东西?
In Windows environment, is Boost's scoped mutex using WinAPI's critical sections, or something else?
的boost ::互斥
的当前版本既不使用一个Win32 CRITICAL_SECTION
,也不是一个Win32的互斥。相反,它使用原子操作和一个Win32事件用于阻断等待
The current version of boost::mutex
uses neither a Win32 CRITICAL_SECTION
, nor a Win32 Mutex. Instead, it uses atomic operations and a Win32 Event for blocking waits.
旧版本(1.34.1提升和以前)是大约 CRITICAL_SECTION
的包装上的Windows。
Older versions (boost 1.34.1 and prior) were a wrapper around CRITICAL_SECTION
on Windows.
顺便说一下,该互斥本身不范围。在的boost ::互斥:: scoped_lock的
键入,并在最近的版本中,的boost :: lock_guard<提高::互斥>
和的boost :: unique_lock<提高::互斥方式>
锁定一个互斥体,以确保您不要忘记解锁提供RAII包装
Incidentally, the mutex itself is not scoped. The boost::mutex::scoped_lock
type and, in recent versions, boost::lock_guard<boost::mutex>
and boost::unique_lock<boost::mutex>
provide RAII wrappers for locking a mutex to ensure you don't forget to unlock it.
的的boost :: lock_guard&LT;&GT;
和的boost :: unique_lock&LT;&GT;
模板与任何类型的工作,与锁()
和解锁()
成员函数,如果需要的话,您可以与跨进程互斥使用它们。
The boost::lock_guard<>
and boost::unique_lock<>
templates work with any type with lock()
and unlock()
member functions, so you can use them with inter-process mutexes if desired.