生产者-消费者问题是操作系统课程教学中进程同步与互斥的经典问题,深刻理解此问题对理解操作系统中的进程管理具有重要意义。文章应用可视化的方法、基于多线程方式,对生产者-消费者问题进行了模拟,并通过实际测试比较了生产者、消费者之间设置单一互斥信号量与设置两个互斥信号量两种不同方式对程序运行效率的影响。在给学生以直观映像的同时,引导学生对此问题进行深入思考,激发学生的创新意识。
Producer-consumer problem is a classic example of processes synchronization and mutual exclusion in teaching of operating system. Deep understanding that is of great significance for right understanding of the process management. In this paper, a multi-threaded based simulation programming of this problem is presented. Two different semaphore mechanisms: producer and consumer processes with shared mutex or two different mutexes, are compared on the impact of operational efficiency by actual test. In addition to a visual image to students, it can also guide students on the problem in-depth reflection and inspire their awareness of innovation.