ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > zstu-(2021-2022)-1 > student homework directories > 2019329621196麻宣政 >
2019329621196麻宣政homework5 Version 0
👤 Author: by 1436830195qqcom 2021-12-29 08:37:22
Design and share access data according to my own case. Concurrent access to shared data may result in data inconsistency.Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes.When degining code we can add a variable counter, initialized to 0 and incremented each time a new item is added to the buffer.
The code list as the following:
Shared data
typedef .... item;
item buf[MAX];
int d_in, d_out, num;
d_in=0;
d_out=0;
num=0;
Producer process
while(true) {
...
produce an item in nextp
...
while(num==n)
no-op;
buf[d_in]=nextp;
d_in=(d_in+1)%n;
num++;
}
Consumer process
while(true) {
while(num==0)
no-op;
nextc=buf[d_out];
d_out=(d_out+1)%n;
num--;
...
consume the item in nextc
...
}
The statements:
num++;
num--;

Please login to reply. Login

Reversion History

Loading...
No reversions found.