Question: Implement a solution to the Reader - Writer problem with password authentication using threads and semaphores in C programming language on a Linux platform. The

Implement a solution to the Reader-Writer problem with password authentication using threads and semaphores in C programming language on a Linux platform. The program should create two types of threads: reader and writer. Each thread must acquire a unique password from a table to access the database (a global variable BUFFER). There can be a minimum of 1 and a maximum of 9 readers/writers. So, any combination of readers and writers is possible, such as (1,1),(1,2)...(1,9),(2,1)...(9,1),..., or (5,5). The writers can write a random number in the range 0-9999 to BUFFER, each time it has access to it. Let each writer/reader sleep 1 second before consecutive writing/reading. The password table is filled with 10 random 6-digit numbers before use, in the main process. Each reader/writer is allocated a unique password from the table. The shared resource (BUFFER) should only be accessible after being checked for the password. Furthermore, create equal number of dummy readers and writers with random passwords, not included in the password table. For example, if there are 2 readers and 3 writers, there will be 2 dummy readers and 3 dummy writers. Ensure exclusive access to the password file to prevent race conditions and duplicate passwords. Ensure that readers can access the resource simultaneously with the correct password without interfering with each other. Ensure that writers have exclusive access to the resource with the correct password, preventing simultaneous access by readers or other writers.
Program Output:
Number of readers thread: 2
Number of writers thread: 1
1 real writer thread 41
2 real reader thread 41
1 real reader 41
1 dummy reader No permission
2 dummy reader No permission
1 real writer 8467
1 dummy writer No permission
1 real reader 8467
Correct Output:
Number of readers thread: 2
Number of writers thread: 1
1 real writer thread 41
2 real reader thread 0
1 real reader 41
1 dummy reader No permission
2 dummy reader No permission
1 real writer 8467
1 dummy writer No permission
1 real reader 8467
Description for this sample output:
There are 2 reader threads: Thread 1, and Thread 2
There are 1 writer thread: Thread 1
If the thread number is the same(id) it's writer and reader are a pair which means when thread 1 is a writer thread, and writes 41, the reader thread will read 41. Since thread 2 is a different thread, it can't read the value 41, so it will print 0.

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!