Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This programming question is about semaphore Please create two threads t1 and t2. tl and t2 share an integer data counter. The job oftl is

image text in transcribed

This programming question is about semaphore Please create two threads t1 and t2. tl and t2 share an integer data counter. The job oftl is to increase the value of counter by 1 when tl is scheduled. The job of t2 is to decrease the value of counter by 1 when t2 is scheduled Because counter is a critical section, you need to use semaphore to implement mutual exclusion between tl and t2 Here is the API you may use sem init: initialize an unnamed semaphore sem wait: lock a semaphore, which is equivalent to the P operation sem post: unlock a semaphore, which is equivalent to the V operation sem destroy: destroy an unnamed semaphore Here is the basic structure of the program int counter; /Mshared between t1 and t2 main) Create semaphore, Create ti, Create t2, Destroy semaphore, thread tl routine0 while (1) PO, Increase counter by 1; Output the value of counter; thread t2 routine while (1) Decrease counter by 1; Output the value of counter; VO

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 Management System MCQs Multiple Choice Questions And Answers

Authors: Arshad Iqbal

1st Edition

1073328554, 978-1073328550

More Books

Students also viewed these Databases questions

Question

=+Understand the fi eld of comparative IHRM.

Answered: 1 week ago

Question

=+j Understand different types of regions in the world.

Answered: 1 week ago