Thread Safety in the Standard C++ Library(From MSDN)

When /MT , /MTd, /MD, or /MDd is used, the following thread-safety rules are in effect:

Container Classes (vector, deque, list, queue, stack , priority_queue, valarray, map, multimap, set, multiset, basic_string, bitset) and complex

For reads to the same object, the object is thread safe for reading:

  • From one thread at a time when no writers on other threads.
  • From many threads at a time when no writers on other threads.

For writes to the same object, the object is thread safe for writing from one thread when no readers on other threads

For reads to different objects of the same class, the object is thread safe for reading:

  • From one thread at a time.
  • From one thread at a time when no writers on other threads.
  • From many threads at a time.
  • From many threads at a time when no writers on other threads.

For writes to different objects of the same class, the object is thread safe for writing:

  • From one thread when no readers on other threads.
  • From many threads.
iostream Classes

Note that reading from a stream buffer is not considered to be a read operation. It should be considered as a write operation, because this changes the state of the class.

For reads to the same object, the object is thread safe for reading:

  • From one thread at a time when no writers on other threads.
  • From many threads at a time when no writers on other threads.

For writes to the same object, , the object is thread safe for writing:

  • From one thread when no readers on other threads.
  • From many threads (when accesses are limited to stream buffers).

For reads to different objects of the same class, , the object is thread safe for reading:

  • From one thread at a time.
  • From one thread at a time when no writers on other threads.
  • From many threads at a time.
  • From many threads at a time when no writers on other threads.

For writes to different objects of the same class, the object is thread safe for writing:

  • From one thread when no readers on other threads
  • From many threads
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值