私のクラスのようにすべての関数を宣言するだけで十分なので、 Experimental Transactional Memory TS からtransaction_safe
のトランザクションでスレッドセーフとして使用できますか?atomic_noexcept, atomic_cancel, atomic_commit
知られているように、Experimental C++ 標準ライブラリには Transactional Memory TS (ISO/IEC TS 19841:2015) があります。簡単な例はこちら: http://en.cppreference.com/w/cpp/language/transactional_memory
また、トランザクション メモリの C++ 拡張機能の技術仕様もあります: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4514.pdf
34ページ:
23.4 Associative containers [associative]
23.4.4 Class template map [map]
23.4.4.1 Class template map overview [map.overview]
In 23.4.4.1 [map.overview], add "transaction_safe" to the declarations of all
variants of the begin and end member functions and to
the declarations of size, max_size, and empty.
つまり、トランザクショナル メモリが C++ 標準にコミットする場合、単純にこのようなことを行うことができ、それはスレッド セーフになりますか?
#include<map>
#include<thread>
std::map<int, int> m;
int main() {
std::thread t1([&m]() {
atomic_cancel
{
m[1] = 1; // thread-safe
}
} );
t1.join();
return 0;
}
残念ながら、GCC 6.1atomic_cancel {}
のキーを使用しても例を再現できません: https://godbolt.org/g/UcV4wI-fgnu-tm
そして、一部のクラスのようにすべての関数を宣言するだけで十分なtransaction_safe
ので、スレッドセーフとして使用できます-スコープ内で呼び出す場合: atomic_cancel { obj.func(); }
?