auto commit
This commit is contained in:
parent
cb1f03082e
commit
3c08c153be
|
@ -457,12 +457,12 @@ void writer() {
|
|||
}
|
||||
}
|
||||
```
|
||||
|
||||
以下内容由 [@Bandi Yugandhar](https://github.com/yugandharbandi) 提供。
|
||||
|
||||
The first case may result Writer to starve. This case favous Writers i.e no writer, once added to the queue, shall be kept waiting longer than absolutely necessary(only when there are readers that entered the queue before the writer).
|
||||
|
||||
|
||||
|
||||
|
||||
```c
|
||||
```source-c
|
||||
int readcount, writecount; //(initial value = 0)
|
||||
semaphore rmutex, wmutex, readLock, resource; //(initial value = 1)
|
||||
|
||||
|
@ -488,7 +488,6 @@ void reader() {
|
|||
up(&rmutex); //release exit section for other readers
|
||||
}
|
||||
|
||||
|
||||
//WRITER
|
||||
void writer() {
|
||||
<ENTRY Section>
|
||||
|
@ -514,10 +513,9 @@ void writer() {
|
|||
|
||||
We can observe that every reader is forced to acquire ReadLock. On the otherhand, writers doesn’t need to lock individually. Once the first writer locks the ReadLock, it will be released only when there is no writer left in the queue.
|
||||
|
||||
|
||||
From the both cases we observed that either reader or writer has to starve. Below solutionadds the constraint that no thread shall be allowed to starve; that is, the operation of obtaining a lock on the shared data will always terminate in a bounded amount of time.
|
||||
|
||||
```c
|
||||
```source-c
|
||||
int readCount; // init to 0; number of readers currently accessing resource
|
||||
|
||||
// all semaphores initialised to 1
|
||||
|
@ -542,7 +540,6 @@ void writer()
|
|||
// </EXIT>
|
||||
}
|
||||
|
||||
|
||||
void reader()
|
||||
{
|
||||
down(&serviceQueue); // wait in line to be serviced
|
||||
|
@ -568,10 +565,9 @@ void reader()
|
|||
up(&readCountAccess); // release access to readCount
|
||||
}
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
### 2. 哲学家进餐问题
|
||||
|
||||
<div align="center"> <img src="../pics//a9077f06-7584-4f2b-8c20-3a8e46928820.jpg"/> </div><br>
|
||||
|
|
Loading…
Reference in New Issue
Block a user