#include <stdio.h>
#include <thread>
#include <mutex>
#include <condition_variable>
using namespace std;
#define SIZE 8
size_t buffer = 0;
mutex mx;
condition_variable_any cvFull;
condition_variable_any cvEmpty;
void Producer() {
mx.lock();
while (buffer==SIZE) cvFull.wait(mx);
++buffer;
cvEmpty.notify_all();
mx.unlock();
}
void Consumer() {
mx.lock();
while (buffer==0) cvEmpty.wait(mx);
--buffer;
cvFull.notify_all();
mx.unlock();
}
void Producer_Thread() {
while (true) {
Producer();
}
}
void Consumer_Thread() {
while (true) {
Consumer();
}
}
int main() {
thread t_pro(Producer_Thread);
thread t_con(Consumer_Thread);
t_pro.join();
t_con.join();
return 0;
}