2020-10-05

    科技2022-08-05  107

    201919102011 王慧颖

    semaphore plate=l, apple=0, orange=0; dad() { //父亲进程 while (1) {prepare an apple;P(plate) ; //互斥向盘中取、放水果 put the apple on the plate; //向盘中放苹果V(apple); //允许取苹果 } } mom() { // 母亲进程 while(1) { prepare an orange; P(plate); //互斥向盘中取、放水果 put the orange on the plate; //向盘中放橘子V(orange); //允许取橘子 } } son() { //儿子进程 while(1) { P(orange) ; //互斥向盘中取橘子 take an orange from the plate; V(plate); //允许向盘中取、放水果 eat the orange; } } daughter () { //女儿进程 while(1) {P(apple); // 互斥向盘中取苹果 take an apple from the plate; V(plate); //运行向盘中取、放水果eat the apple; } }

    Processed: 0.016, SQL: 8