Skip to content

Proper use of absl::Condition #1850

Answered by derekmauro
rogeeff asked this question in Q&A
Discussion options

You must be logged in to vote

// auto reached = [this, current]() {
// mu_.AssertReaderHeld(); // For annotalysis.
// return processed_ >= current;
// };
// mu_.Await(Condition(&reached));

class Foo {
 public:
  void WaitForValue(int v) {
    auto reached = [this, v]() {
      return field_ == v;
    };
    absl::MutexLock lock(&guard_);
    guard_.Await(absl::Condition(&reached));
  }

 private:
  absl::Mutex guard_;
  int field_ ABSL_GUARDED_BY(guard_);
};

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rogeeff
Comment options

Answer selected by rogeeff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants