 std::condition_variable: #include <iostream> #include <thread> #include <mutex> #include <condition_variable> #include <queue> #include <chrono>  std::mutex mutex; std::queue<int> queue; int counter;  void loadData() {     while(true)     {         std::unique_lock<std::mutex> lock(mutex);         queue.push(++counter);         lock.unlock();         std::this_thread::sleep_for(std::chrono::seconds(0));     } }  void writeData() {     while(true)     {         std::