Write a multi-threaded C program that gives readers priority over writers concerning a shared (global) variable. Essentially, if any readers are waiting, then they have priority over writer threads - writers can only write when there are no readers.
In this case
i. No WRITER and READER thread will be created
ii. No read or write operation done
iii. Program will be terminated
In this case
i. No WRITER and READER thread will be created
ii. No read or write operation done
iii. Program will be terminated
In This Case:
i. Only READER thread will be created
ii. No WRITER thread is created
iii. No updating of the Shared Variable
iv. Only READER is reading the shared variable. From the example given above R1, R0 wait for some times. Then R1 read 1 time and R0 read 2 times. Finally Shared variable value will be remain same.
In This Case:
i. Only WRITER thread is created
ii. No READER thread is created
iii. No reading of the shared variable
iv. Only WRITER is updating the shared variable. From the same example given above W1, W0 will make change on the shared variable. W1 writes 2 times and W0 writes 1 time. Finally shared variable value will be changes/updated.
In This Case:
i. Both READER and WRITER threads created
ii. Any WRITER can update the Shared variable any number of times
iii. Any READER can read that Value any number of times
iv. In the screen slot, W0 wait for some random times. Then he has the choice to update the variable any number of times with any number. Here W0 update for 2 times. He added 1st times with value 5.
In This Case:
i. Both READER and WRITER threads created
ii. Any WRITER can update the Shared variable any number of times
iii. Any READER can read that Value any number of times
iv. In this screen slot, W0 wait for some time and add some value with shared variable. Then R0 given the choice to read any number of times. Then again, the turn of next writer i.e. W1 came.
In This Case:
i. Both READER and WRITER threads created
ii. Any WRITER can update the Shared variable any number of times
iii. Any READER can read that Value any number of times
iv. In this example, W0 wait for some times and update the variable. Then R0, R1 also wait then read the variable any number of times.
In This Case:
i. User unable to take any input
ii. No READER and WRITER thread were created
iii. We will not get output as we expected
iv. But get the Shared variable value as 0
ii. User taken the initial value of share variable(S) as 10
iii. User taken the no. of reader(R) is 2 as input i.e. R0 & R1
iv. User taken the no. of writer(W) is 2 as input i.e. W0 & W1
v. Now READER and WRITER threads were created successfully
vii. W0 wait for some random time. Then he chooses that he will update S two time. Fist time he add 7 to S. S = 10 + 7 = 17 then second time he add 8 to S. Now S = 17 + 8 = 25. So, New updated value is 25.
ix. Now R0 & R1 wait for some random times. Then R0 wants that he wants to read the shared variable 2 time. Then R1 read for 3 times. At this instant, 1 reader is present. Then W1 wait for some times and he want to add 9 to the shared variable for 1 time. S = 25 + 9 = 34.
x. Finally, after joining the thread, we got the shared variable value as 34.