template<typename T, typename RcuTraits>
class rcu::Variable< T, RcuTraits >
Read-Copy-Update variable.
- See also
- Based on ideas from http://www.drdobbs.com/lock-free-data-structures-with-hazard-po/184401890 with modified API.
A variable with MT-access pattern "very often reads, seldom writes". It is specially optimized for reads. On read, one obtains a ReaderPtr<T> from it and uses the obtained value as long as it wants to. On write, one obtains a WritablePtr<T> with a copy of the last version of the value, makes some changes to it, and commits the result to update current variable value (does Read-Copy-Update). Old version of the value is not freed on update, it will be eventually freed when a subsequent writer identifies that nobody works with this version.
- Note
- There is no way to create a "null"
Variable
.
Example usage:
constexpr int kOldValue = 1;
constexpr auto kOldString = "Old string";
constexpr int kNewValue = 2;
constexpr auto kNewString = "New string";
struct Data {
int x;
std::string s;
};
{
auto ro_ptr = data.
Read();
ASSERT_EQ(ro_ptr->x, kOldValue);
ASSERT_EQ(ro_ptr->s, kOldString);
}
{
ptr->x = kNewValue;
ptr->s = kNewString;
ptr.Commit();
}
- See also
- Synchronization Primitives
- Template Parameters
-
- Examples
- samples/config_service/config_service.cpp.
Definition at line 373 of file rcu.hpp.
template<typename T , typename RcuTraits >
template<typename... Args>
Obtain a smart pointer to a newly in-place constructed value, but does not replace the current one yet (in contrast with regular Emplace
).
Definition at line 428 of file rcu.hpp.