Back to UNIX page

POSIX Threads

Readers - Writers problem with priority for writers

Write an application that solves the readers - writers problem with priority for writers. Program creates n reader threads and m writer threads which work on pagefile. All threads are joinable. Each reader can read from the file, each writer can write to the file. A reader can read simultaneously with other readers, a writer writes exclusively (this means that no other thread - neither reader nor writer - can use the file at the same time). Writers have priority - this means that if any writer wants to write no reader can start reading. There is no priority between writers. Writers' job is to write a single randomly selected unsigned short integer (0 - USHRT_MAX) to the file, readers' job is to read this value and send it to standard output. Access to standard output should be made within a critical section. All threads must announce their file access on standard output. Threads wait a random amount of time between 400 and 750 ms at the end of each iteration.

Hint: - Page 12

The application should terminate on SIGINT (C-c), all threads must end their jobs before terminating. All resources must be properly released.

Should any of (n, m, pagefile) parameters not be supplied, program prints usage information and exits.

Sample output: here

Task will be graded by Jurek Bartuszek. Copy your solutions to /home2/samba/bartuszekj/unix/ .

Extra attention should be payed to:

Back to UNIX page