Closed YuezhenQin closed 11 months ago
进程同步的诀窍是“前VP后”。 P (wait) 是申请一个资源。V (signal) 是释放一个资源。PV 成对出现。
1.确认主体 t1, t2; 2.确认前驱关系; 3.完成程序设计。
typedef struct { int value; struct process *L; } semaphore;
void wait(semaphore S) { S.value --; while (value < 0) { block (S.L); } }
void signal(semaphore S) { S.value ++; while (value <= 0) { wakeup(S.L); } }
进程同步的诀窍是“前VP后”。 P (wait) 是申请一个资源。V (signal) 是释放一个资源。PV 成对出现。
1.确认主体 t1, t2; 2.确认前驱关系; 3.完成程序设计。
typedef struct { int value; struct process *L; } semaphore;
void wait(semaphore S) { S.value --; while (value < 0) { block (S.L); } }
void signal(semaphore S) { S.value ++; while (value <= 0) { wakeup(S.L); } }