c++concurrencystlc++14transactional-memory

Why are ordered std::map and ordered std::set not invited to make transaction_safe?


As known there are Transactional Memory TS (ISO/IEC TS 19841:2015) in the Experimental C++: Is it enough to declare a function as transaction_safe, so they can be used thread-safe?

And operator[] declared as transaction_safe only for containers: std::vector, std::unordered_map, std::unordered_multimap, std::unordered_set, std::unordered_multiset, std::deque - Taken from n4514: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4514.pdf

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.

But why is not there operator[] declared as transaction_safe for std::map and std::set (but there are for unordered_map/unordered_set)?

And why there are add "transaction_safe" to the declarations of all variants of the begin and end member functions for std::map and std::set?

Iterators begin and end are very necessary for the std::array, std::vector or std::list, but not for an associative array. In an associative array required find or find-and-modify functions: find, at, insert, erase and operator[]. Without them, it does not make sense.

Why are ordered std::map and ordered std::set not invited to make transaction_safe?


Solution

  • That unordered_meow::operator[] is specified to be unconditionally transaction-safe is a defect.

    Instead, map::operator[]'s transaction safety is governed by the addition to [container.requirements.general]:

    Unless unconditionally specified to be transaction-safe, a function in this Clause is transaction-safe if all required operations are transaction-safe. [ Note: This includes operations on the element type, on std::allocator_traits, and on Compare, Pred, or Hash objects, depending on the respective function. -- end note ]