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.
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

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

Why does codification presume a democratic setting?

Answered: 1 week ago

Question

Conduct a needs assessment. page 283

Answered: 1 week ago