mmcshane / leftright Goto Github PK
View Code? Open in Web Editor NEWA C++ implementation of left-right concurrency control
A C++ implementation of left-right concurrency control
Definition of functions atomic_reader_registry::depart, atomic_reader_registry::arrive, atomic_reader_registry::empty misses inline keyword.
Non template class function declared in header must be inline.
Hi i have decided to test leftright implementation of yours.
write thread updates leftright protected Big struct.
read thread reads updated values and checks if read struct is half updated.
I have run this test on x86_64 cpu and i read half updated values.
I dont think this is the expected behaviour but want to ask anyways.
Is this expected behaviour?
Sample output
failed 23096 23097 23097 23097
failed 72977 72977 72977 72979
failed 109959 109959 109959 109960
Here is the test code.
struct Big
{
private:
alignas(std::hardware_destructive_interference_size) int a1{};
alignas(std::hardware_destructive_interference_size) int a2{};
alignas(std::hardware_destructive_interference_size) int a3{};
alignas(std::hardware_destructive_interference_size) int a4{};
public:
void add1()
{
a1 += 1;
a2 += 1;
a3 += 1;
a4 += 1;
}
void print() const
{
std::cout << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << std::endl;
}
void check() const
{
if ((a1 == a2) && (a1 == a3) && (a1 == a4))
{
}
else
{
std::cout << "failed ";
this->print();
}
}
};
template <typename T>
struct leftright_wrap
{
mpm::leftright<T> lr;
auto read() const noexcept
{
return lr.observe([](const auto &val) noexcept
{ return val; });
}
auto write(const T &t) noexcept
{
lr.modify([&t](auto &val) noexcept
{ val = t; });
}
};
int main()
{
leftright_wrap<Big> lr;
std::thread read_([&lr]
{
while (true)
{
auto a = lr.read();
a.check(); //! should not see half updated value
}
}
);
std::thread write_([&lr]
{
Big big{};
while (true)
{
big.add1();
lr.write(big);
}
}
);
read_.join();
write_.join();
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.