Skip to content

Commit 65be873

Browse files
fix: Improve concurrency control by adding wait and notify mechanisms
Signed-off-by: FrozenlemonTee <1115306170@qq.com>
1 parent bcfe31e commit 65be873

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

examples/ex05_concurrency_policy.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int main() {
4949
for (int writer = 0; writer < kWriterThreads; ++writer) {
5050
workers.emplace_back([&, writer]() {
5151
while (!start.load(std::memory_order_acquire)) {
52+
start.wait(false, std::memory_order_relaxed);
5253
}
5354

5455
for (int n = 0; n < kIterationsPerThread; ++n) {
@@ -64,6 +65,7 @@ int main() {
6465
for (int reader = 0; reader < kReaderThreads; ++reader) {
6566
workers.emplace_back([&, reader]() {
6667
while (!start.load(std::memory_order_acquire)) {
68+
start.wait(false, std::memory_order_relaxed);
6769
}
6870

6971
for (int n = 0; n < kIterationsPerThread; ++n) {
@@ -100,6 +102,7 @@ int main() {
100102
}
101103

102104
start.store(true, std::memory_order_release);
105+
start.notify_all();
103106

104107
for (auto &worker : workers) {
105108
worker.join();

0 commit comments

Comments
 (0)