junxnone / linux

Linux wiki
https://junxnone.github.io/linux/
0 stars 0 forks source link

Linux IPC Semaphore #88

Open junxnone opened 3 years ago

junxnone commented 3 years ago

Reference

Brief

PV 操作

用于互斥

进程 1 & 2 不能同时进入临界区,当有一个先进入后,另一个只能等待资源释放

用于同步

//Write
while(TRUE){
     P(empty);
     write_data();
     V(full);
}

//Read
while(True){
   P(full);
   read_data();
   V(empty);
}