semaphore mutex = 1;
semaphore db = 1;
int readercount = 0;
void Reader()
{
while(true)
{
P(mutex);
readercount ++;
if(readercount == 1)
P(db);
V(mutex);
//讀數據
P(mutex); //讀完了要走
readercount --;
if(readercount == 0)
V(db);
V(mutex);
}
}
void Writer()
{
P(db);
//寫數據
V(db);
}
PV讀者寫者問題
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Indexing with Glimpse
Glimpse, a simple but effective indexing package, can help you find partic
Anglewing_nwpu
2020-07-07 04:44:16
2.3進程的同步概念和經典同步互斥問題
坚持学习的你
2020-07-03 17:49:18
2.1進程和線程的概念
坚持学习的你
2020-07-03 17:49:18
Operating System 作業-02
Ho Lee
2020-07-03 02:46:33
MIT JOS # RoundRobin Scheduling#
JasonLeaster
2020-06-28 10:12:31
The File System in JOS
JasonLeaster
2020-06-28 10:12:31
鳥叔的linux私房菜:第0章 計算機概論學習筆記(Learning Notes for Basic Computer Theory)
蓝色枫魂
2020-06-28 00:43:34
Configure the network of CentOS
Victor01
2020-06-21 20:43:34
Gnome桌面安裝 - centos
Victor01
2020-06-21 20:04:10
Cache Blocking
Dark-Rich
2020-06-20 23:28:40
理解解釋器中的JIT機制
原始代碼 long add4(long num) { return num + 4; } JIT代碼 0x48, 0x89, 0xf8, // mov %rdi, %rax 0x48, 0
Dark-Rich
2020-06-20 21:24:36
OS161 源代碼閱讀-1
DanceFire
2020-06-13 01:54:38
C++/C程序內存佈局及函數棧結構
toponedison
2020-06-07 14:18:01