title: Clang thread safety with std::condition variable
body: <p>I have the following mutex classes (hopefully) implemented after the clang thread safety model. (<a href="http://clang.llvm.org/docs/ThreadSafetyAnalysis.html" rel="nofollow noreferrer">http://clang.llvm.org/docs/ThreadSafetyAnalysis.html</a>)</p>
  
  <pre><code>class CAPABILITY( "mutex" ) Mutex : public std::mutex
  {
    public:
      void lock() ACQUIRE()
      {
          std::mutex::lock();
      }
  
      void unlock() RELEASE()
      {
          std::mutex::unlock();
      }
  };
  
  class SCOPED_CAPABILITY LockGuard : public std::unique_lock&lt; std::mutex &gt;
  {
    public:
          LockGuard( Mutex&amp; mu ) ACQUIRE( mu ) : std::unique_lock&lt; std::mutex &gt;( mu )
          {
          }
  
          ~LockGuard() RELEASE()
          {
          }
  };
  </code></pre>
  
  <p>The usage is as follows:</p>
  
  <pre><code>class Barrier
  {
      ...
  
      Mutex mutex_;
      std::condition_variable cv_ GUARDED_BY( mutex_ );
      std::size_t min_count_ GUARDED_BY( mutex_ );
      std::size_t count_ GUARDED_BY( mutex_ );
  
      bool Barrier::waitFor( const std::chrono::microseconds&amp; duration )
      {
          LockGuard lock( mutex_ );
          if ( count_ &gt;= min_count_ )
          {
              return true;
          }
          else
          {
              // WARNING IS IN THE LINE BELOW
              return cv_.wait_for( lock, duration, [this]() { return count_ &gt;= min_count_; } );  
          }
      }
  };
  </code></pre>
  
  <p>I get the clang warning:
  <code>warning: reading variable 'count_' requires holding mutex 'mutex_' [-Wthread-safety-analysis]</code>.</p>
  
  <p>Is the warning of the compiler (clang 3.8 with -Wthread-safety) correct? If yes, how exactly does the violation happen?</p>