Implement a solution via semaphores and threads to the n


Implement a solution via semaphores and threads to the n reader 1 writer problem. Fairness always matters. You will accept the number of readers from the command line. In no case will more than 12 readers be used and always at least 1 reader will be used. Each reader must access a shared counter value 250000000 times in the C.S. For convenience code is below that will do this. A reader reads just one time and a writer writes just one time. Each reader needs to print its name when done. The writer will update the value 25000 times and print done. The writer will also set a shared flag, in-cs, when it enters the critical section and reset it just before it leaves the critical section. The reader must, upon entering the critical section, check this flag and write an error message if the flag is set.

You can help us out for testing by using a version of the following code to give the writer a chance to run before all threads (if you want).

k = (int) (numofReaders/2);

for(i = 0; i < k; i++){

pthread_createacreaders[i], icattr[01, reader_thread, (void*) i);

}

/* Create the writer thread */

pthread_create (&writer [0] , tattr [0] , writer_thread , NULL) ; for(i = k ; i < num0f Readers ; i++) {

pthread_create (&readers , &a= [0] , reader_thread, (void*) i) ;

}

void relaxandspendtime()

{

int i;

for(i = 0; i < 250000000; i++) i=i;

}

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Implement a solution via semaphores and threads to the n
Reference No:- TGS02201851

Expected delivery within 24 Hours