Posted on 2010-08-25 18:36
S.l.e!ep.¢% 閱讀(1139)
評論(0) 編輯 收藏 引用 所屬分類:
C++
Boost ? 文檔對于 ? shared_ptr ? 的線程安全有一段專門的記述,內(nèi)容如下:
shared_ptr ? objects ? offer ? the ? same ? level ? of ? thread ? safety ? as ? built-in ? types. ? A ? shared_ptr ? instance ? can ? be ? "read " ? (accessed ? using ? only ? const ? operations) ? simultaneously ? by ? multiple ? threads. ? Different ? shared_ptr ? instances ? can ? be ? "written ? to " ? (accessed ? using ? mutable ? operations ? such ? as ? operator= ? or ? reset) ? simultaneosly ? by ? multiple ? threads ? (even ? when ? these ? instances ? are ? copies, ? and ? share ? the ? same ? reference ? count ? underneath.)
Any ? other ? simultaneous ? accesses ? result ? in ? undefined ? behavior.
翻譯為中文如下:
shared_ptr ? 對象提供與內(nèi)建類型一樣的線程安全級別。一個(gè) ? shared_ptr ? 實(shí)例可以同時(shí)被多個(gè)線程“讀”(僅使用不變操作進(jìn)行訪問)。不同的 ? shared_ptr ? 實(shí)例可以同時(shí)被多個(gè)線程“寫入”(使用類似 ? operator= ? 或 ? reset ? 這樣的可變操作進(jìn)行訪問)(即使這些實(shí)例是拷貝,而且共享下層的引用計(jì)數(shù))。
任何其它的同時(shí)訪問的結(jié)果會導(dǎo)致未定義行為。