Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
Part of Sample Run:
Number of readers: 4
Number of writers: 6
Thread No Validity(real/dummy) Role(reader/writer) Value read/written
1 real reader 0
1 dummy reader No permission
2 real reader 0
2 dummy reader No permission
3 real reader 0
3 dummy reader No permission
4 real reader 0
4 dummy reader No permission
1 real writer 979
1 dummy writer No permission
2 real writer 4793
3 real writer 7455
2 dummy writer No permission
3 dummy writer No permission
4 real writer 4454
4 dummy writer No permission
5 dummy writer No permission
5 real writer 1250
6 real writer 3857
6 dummy writer No permission
1 real reader 979
2 real reader 4793
3 real reader 7455
4 real reader 4454
1 dummy reader No permission
2 dummy reader No permission
3 dummy reader No permission
4 dummy reader No permission
1 real writer 1160
1 dummy writer No permission
2 real writer 1658
3 real writer 1691
2 dummy writer No permission
3 dummy writer No permission
4 real writer 7238
4 dummy writer No permission
5 dummy writer No permission
5 real writer 6350
6 real writer 5839
6 dummy writer No permission
1 real reader 1160
2 real reader 1658
3 real reader 1691
4 real reader 7238
2 dummy reader No permission
3 dummy reader No permission
4 dummy reader No permission

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

How can you listen critically to others public speeches?

Answered: 1 week ago