If someone could help provide a detailed explanation for this please. There are similar posts but the explanations are a bit hard to understand.
1)
if updater is updating, this means s_db is 0, and P(s_db) will result in wait. So browser process will be blocked in the if condition if(count==1) which is in s_count semaphore
2)
We can see that the first browser that will browse will call P(s_db) and set count = 1. Now all this happens inside first P(s_count) and V(s_count). We can see that the semaphore isn't on hold for any browser process (means it is released after updating count). This means that multiple browser can pass P(s_count) and browse simultaneously
3)
for updater process, we have a binary semaphore s_db which will be held back by first updater process. So only one updater can access at once
4)
This isn't necessary. Assume browser process 1,2,3,4 (arrives in same order). 1 will set count to 1 and call P(s_db) and let them leave in order 1,2,3,4. This time 4 will set count to 0 and call V(s_db)
5) This solution is definitely free of deadlock since multiple browser process can read db at once but only one updater can update it (see part a,b,c for explanation). There can be situation where there are huge number of browser process and they arrive,leave and then arrive again before count drops to 0. which means that the s_db semaphore is always 0. so updater process will wait indefinitely if not starve
6)
This would result in inconsistency. Consider 2 broser process access count variable simultaneously (which was 0) now both increment it and it become 2. so the if condition will not execute and s_db remains 1 which allow updater process to update db while browser process was reading db. I am assuming the context switch between the processes at the line count++
1)
if updater is updating, this means s_db is 0, and P(s_db) will
result in wait. So browser process will be blocked in the if
condition if(count==1) which is in s_count semaphore
2)
We can see that the first browser that will browse will call
P(s_db) and set count = 1. Now all this happens inside first
P(s_count) and V(s_count). We can see that the semaphore isn't on
hold for any browser process (means it is released after updating
count). This means that multiple browser can pass P(s_count) and
browse simultaneously
3)
for updater process, we have a binary semaphore s_db which will be
held back by first updater process. So only one updater can access
at once
4)
This isn't necessary. Assume browser process 1,2,3,4 (arrives in
same order). 1 will set count to 1 and call P(s_db) and let them
leave in order 1,2,3,4. This time 4 will set count to 0 and call
V(s_db)
5) This solution is definitely free of deadlock since multiple browser process can read db at once but only one updater can update it (see part a,b,c for explanation). There can be situation where there are huge number of browser process and they arrive,leave and then arrive again before count drops to 0. which means that the s_db semaphore is always 0. so updater process will wait indefinitely if not starve
6)
This would result in inconsistency. Consider 2 broser process
access count variable simultaneously (which was 0) now both
increment it and it become 2. so the if condition will not execute
and s_db remains 1 which allow updater process to update db while
browser process was reading db. I am assuming the context switch
between the processes at the line count++
If someone could help provide a detailed explanation for this please. There are similar posts but...
pleasw answer as soon as possible . this is for my exam practice .
please read the code and answer the question
In a system, there are multiple reader processes which read from a shared file and multiple writer processes which update a shared file. The following variables are shared among all processes: int readCounter; semaphore mutex, writeLock; Reader and writer processes are given in the following C++-like pseudo programs: Reader Process // Non-Critical Section P(mutex); Writer Process // Non-Critical...