Untitled

 avatar
unknown
plain_text
2 months ago
555 B
2
Indexable
// Judge code in terms of correctness

  #include <condition_variable>
  #include <iostream>
  #include <thread>


  std::mutex mutex_;
  std::condition_variable cv_;


  void waiting()
  {
    std::cout << "Waiting " << std::endl;
    std::unique_lock<std::mutex> lock(mutex_);
    cv_.wait(lock);
    std::cout << "Running " << std::endl;
}


void notify()
{
    std::cout << "Notifying" << std::endl;
    cv_.notify_one();
}


int main()
{    
    std::thread t1(waiting);
    std::thread t2(notify);


    t1.join();
    t2.join();


    return 0; 
}
Leave a Comment