Comments (6)
- The ordering of cd and git checkout in the doc is flipped
- the doc refers to
btree_tests/ParallelTools/ParallelTools/Lock.cpp
, which does not exist (it is header only). - ReaderWriterLock2 is not in the Lock header
manually adding ReaderWriterLock2 it compiles and seems to work. Thank you for your help.
from bp-tree.
Thanks for the report. We will try and improve the readme and fix it so it just compiles out of the box.
As for ReaderwriterLock2
the definition is bellow. Let me know if that works and we will update the repo with it as well. You can also just change ReaderWriterLock2
to ReaderWriterLock
. They have some different space usage and performance characteristics in the contested and uncontested cases and I would recommend using ReaderWriterLock2
in most cases.
class ReaderWriterLock2 {
public:
ReaderWriterLock2() : writer(0), readers(0) {}
/**
* Try to acquire a lock and spin until the lock is available.
*/
void read_lock(int cpuid = -1) {
readers++;
while (writer.test(std::memory_order_relaxed)) {
readers--;
writer.wait(true, std::memory_order_relaxed);
readers++;
}
}
void read_unlock(int cpuid) {
readers--;
return;
}
/**
* Try to acquire a write lock and spin until the lock is available.
* Then wait till reader count is 0.
*/
void write_lock() {
// acquire write lock.
while (writer.test_and_set(std::memory_order_acq_rel)) {
writer.wait(true, std::memory_order_acq_rel);
}
// wait for readers to finish
while (readers > 0) {
}
}
void write_unlock(void) {
writer.clear(std::memory_order_release);
writer.notify_all();
return;
}
private:
std::atomic_flag writer{false};
std::atomic<int> readers{};
};
from bp-tree.
After adding the definition to btree.hpp
, I get this (inside function exists
):
../tlx/container/btree.hpp:1748:38: error: too few arguments to function call, single argument 'cpuid' was not specified
leaf->mutex_.read_unlock();
replacing it with ReaderWriterLock
yields the same error
from bp-tree.
my mistake
public:
ReaderWriterLock2() : writer(0), readers(0) {}
/**
* Try to acquire a lock and spin until the lock is available.
*/
void read_lock(int cpuid = -1) {
readers++;
while (writer.test(std::memory_order_relaxed)) {
readers--;
writer.wait(true, std::memory_order_relaxed);
readers++;
}
}
void read_unlock(int cpuid = -1) {
readers--;
return;
}
/**
* Try to acquire a write lock and spin until the lock is available.
* Then wait till reader count is 0.
*/
void write_lock() {
// acquire write lock.
while (writer.test_and_set(std::memory_order_acq_rel)) {
writer.wait(true, std::memory_order_acq_rel);
}
// wait for readers to finish
while (readers > 0) {
}
}
void write_unlock(void) {
writer.clear(std::memory_order_release);
writer.notify_all();
return;
}
private:
std::atomic_flag writer{false};
std::atomic<int> readers{};
};
from bp-tree.
Please check the new main branch, which I cleaned up to remove the dependency on cilk and to make running the experiments smoother. ParallelTools has been updated with ReaderWriterLock2. Here is more documentation:
https://docs.google.com/document/d/1GqQBpYTzSixPAQMfuK8pHyDVL7OjqDHb-Q0u406x894/edit#heading=h.dcbs04rhzkfs
Let us know if there are any questions / issues. Thank you!
from bp-tree.
Thank you for the notes - I have updated the doc to fix the first two issues.
We have updated the ParallelTools repo to include ReaderWriterLock2: https://github.com/wheatman/ParallelTools/blob/main/ParallelTools/Lock.hpp
Please update the submodule to get it.
from bp-tree.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bp-tree.