Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program(not C++ to implement semaphores for the synchronization of threads in Linux environment The program should offer mutual exclusion using semaphores to

image text in transcribed

image text in transcribed

Write a C program(not C++ to implement semaphores for the synchronization of threads in Linux environment The program should offer mutual exclusion using semaphores to a set of two pthreads for a critical section, in this case an access of a data file. One thread prints APPLE and the other pthread prints PEACH into the data file, whenever they get an opportunity to do so. To make believe a critical section, the thread 1 sleeps for 5 system time units, and the thread 2 sleeps for 10 system time units. Use sleep0 for doing the same. After entering the critical section, a thread should print Critical Section on the screen. Besides this, whenever a thread enters or exits the critical section, it should print an appropriate message on the screen identifying itself (thread 1 or 2). The program should prompt the user to type in the name of the data file that is to be accessed by the processes Note: The thread 1 prints APPLE first and then the thread 2 prints PEACH into the data file after the APPLE has been printed. Write a C program(not C++ to implement semaphores for the synchronization of threads in Linux environment The program should offer mutual exclusion using semaphores to a set of two pthreads for a critical section, in this case an access of a data file. One thread prints APPLE and the other pthread prints PEACH into the data file, whenever they get an opportunity to do so. To make believe a critical section, the thread 1 sleeps for 5 system time units, and the thread 2 sleeps for 10 system time units. Use sleep0 for doing the same. After entering the critical section, a thread should print Critical Section on the screen. Besides this, whenever a thread enters or exits the critical section, it should print an appropriate message on the screen identifying itself (thread 1 or 2). The program should prompt the user to type in the name of the data file that is to be accessed by the processes Note: The thread 1 prints APPLE first and then the thread 2 prints PEACH into the data file after the APPLE has been printed

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_2

Step: 3

blur-text-image_3

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

1. What is the major purpose of a user interface system?

Answered: 1 week ago