Question: OPERATING SYSTEM CLASS The program newrace.c contains 5 reader processes and 5 writer processes. Each writer writes a string like 0000000000, 1111111111 or 2222222222 to

OPERATING SYSTEM CLASS

The program newrace.c contains 5 reader processes and 5 writer processes. Each writer writes a string like "0000000000", "1111111111" or "2222222222" to a shared memory area. Each reader reads the string from the shared memory area and display them. However, because of the race condition, the readers get strings with mixed characters such as "4011120001", or "32100011132" most of time. This is incorrect.

(1) Your job is to implement a multiple-readers-single-writer algorithm to prevent the race condition. The correct display results should look like "0000000000", "1111111111", etc. You should use System V semaphores to solve the problem.

(2) You dont have to give readers and writers equal priority.

(3) Your code must be able to allow multiple readers to access the string concorrently.

(4) To learn more about System V semaphores, Search the web about "System V IPC". Pay attention to functions such as semget(), semctl(), semop().

(5) If you want to create a shared variable such as ReaderCount among processes, use the mmap() function. Follow the example in newrace.c.

(6) Use ucfilespace.uc.edu as your test platform.

newrace.c is listed below

#include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #define FILE_SIZE 11 #define NO_PROC 10 int DelayCount = 0; int readerID = 0; int writerID = 0; char* shared_buffer; int Delay100ms = 0; /*------------------------------------------- Delay routines --------------------------------------------*/ void basic_delay() { long i,j,k; for (i=0;i<200L;i++) { for (j=0;j<400L;j++) { k = k+i; } } } /* do some delays (in 100 ms/tick) */ void delay(int delay_time) { int i,j; for (i=0; i                                            

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!