Skip to content

Commit 037a41b

Browse files
authored
Update print-foobar-alternately.cpp
1 parent 959e67b commit 037a41b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

C++/print-foobar-alternately.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ class FooBar {
1010
for (int i = 0; i < n_; ++i) {
1111
{
1212
unique_lock<mutex> l(m_);
13-
wait_.wait(l, [this]() { return !curr_; });
13+
cv_.wait(l, [this]() { return !curr_; });
1414
curr_ = !curr_;
1515
// printFoo() outputs "foo". Do not change or remove this line.
1616
printFoo();
1717
}
18-
wait_.notify_one();
18+
cv_.notify_one();
1919
}
2020
}
2121

2222
void bar(function<void()> printBar) {
2323
for (int i = 0; i < n_; ++i) {
2424
{
2525
unique_lock<mutex> l(m_);
26-
wait_.wait(l, [this]() { return curr_; });
26+
cv_.wait(l, [this]() { return curr_; });
2727
curr_ = !curr_;
2828
// printBar() outputs "bar". Do not change or remove this line.
2929
printBar();
3030
}
31-
wait_.notify_one();
31+
cv_.notify_one();
3232
}
3333
}
3434
private:
3535
int n_;
3636
bool curr_ = false;
3737
mutex m_;
38-
condition_variable wait_;
38+
condition_variable cv_;
3939
};
4040

4141
// Time: O(n)

0 commit comments

Comments
 (0)