void Producer(resource *ir, int item)
{
std::unique_lock lock(ir->mtx);
while (((ir->write_pos + 1) % bufSize)
== ir->read_pos) { // item buffer is full, just wait here.
std::cout not_full).wait(lock); // 生产者等待"产品库缓冲区不为满"这一条件发生.
}
(ir->buf)[ir->write_pos] = item; // 写入产品.
(ir->write_pos)++; // 写入位置后移.
if (ir->write_pos == bufSize) // 写入位置若是在队列最后则重新设置为初始位置.
ir->write_pos = 0;
(ir->not_empty).notify_all(); // 通知消费者产品库不为空.
}