"read" (accessedusing only const operations) simultaneously by multiple threads: OK
"written to" (accessed using mutable operations such as operator=or reset) simultaneosly by multiple threads: OK
"read/written" simultaneosly by multiple threads: Undefined
How to implement:
boost::shared_ptr的win32实现中,没有使用类似mutex机制却能够实现线程安全。
而是使用了BOOST_INTERLOCKED_DECREMENT以及BOOST_INTERLOCKED_INCREMENT
boost::shared_ptr的pthread实现中,使用了mutex机制来保证线程安全。
#define the macro BOOST_SP_DISABLE_THREADS on aproject-wide basis to switch to ordinary non-atomic reference count updates.
You can define the macro BOOST_SP_USE_PTHREADS to turn off thelock-free platform-specific implementation and fall back to the generic pthread_mutex_t-basedcode.