YuezhenQin / 1920

Level of Study: 1
0 stars 0 forks source link

信号量机制 (初始化、P操作、V操作、前VP后) #9

Closed YuezhenQin closed 11 months ago

YuezhenQin commented 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); } }