SlideShare a Scribd company logo
1 of 2
Download to read offline
Write the code segments to create a monitor that has the same behavior as a semaphore.
Monitor semaphore {
//initialization
// synchronization condition variable
// methods
wait ( )
signal ( )
}
Solution
I assume the code is to be written in Java as no language is specified. The solution is below:
public class Monitor_Semaphore {
private int count;
//initialize
public Semaphore (int init)
{
count = init;
}
//signal
synchronized public void S() {
count++;
notify();
}
//wait
synchronized public void W()
throws InterruptedException {
while (count == 0) wait();
count--;
}
public void Method1(){
W();
//critical section
S();
}
}

More Related Content

More from arjunhassan8

Which of the following is NOT a rationale for using mRNA intermed.pdf
Which of the following is NOT a rationale for using mRNA intermed.pdfWhich of the following is NOT a rationale for using mRNA intermed.pdf
Which of the following is NOT a rationale for using mRNA intermed.pdfarjunhassan8
 
Which elements are in series and which are in parallel in Figure P1.3.pdf
Which elements are in series and which are in parallel in Figure P1.3.pdfWhich elements are in series and which are in parallel in Figure P1.3.pdf
Which elements are in series and which are in parallel in Figure P1.3.pdfarjunhassan8
 
What domain is horizontal gene transfer most common within Multiple .pdf
What domain is horizontal gene transfer most common within Multiple .pdfWhat domain is horizontal gene transfer most common within Multiple .pdf
What domain is horizontal gene transfer most common within Multiple .pdfarjunhassan8
 
This problem is based on the B92 method of quantum key distri.pdf
This problem is based on the B92 method of quantum key distri.pdfThis problem is based on the B92 method of quantum key distri.pdf
This problem is based on the B92 method of quantum key distri.pdfarjunhassan8
 
The _ operator can be used to determine a variable address The variab.pdf
The _ operator can be used to determine a variable address The variab.pdfThe _ operator can be used to determine a variable address The variab.pdf
The _ operator can be used to determine a variable address The variab.pdfarjunhassan8
 
The main difference between passive and active transport is the spec.pdf
The main difference between passive and active transport is  the spec.pdfThe main difference between passive and active transport is  the spec.pdf
The main difference between passive and active transport is the spec.pdfarjunhassan8
 
The opposite movement of supination is ___. Pronation flexion exte.pdf
The opposite movement of supination is ___.  Pronation  flexion  exte.pdfThe opposite movement of supination is ___.  Pronation  flexion  exte.pdf
The opposite movement of supination is ___. Pronation flexion exte.pdfarjunhassan8
 
The latter or final stages of an RNA based heriditary world were lik.pdf
The latter or final stages of an RNA based heriditary world were lik.pdfThe latter or final stages of an RNA based heriditary world were lik.pdf
The latter or final stages of an RNA based heriditary world were lik.pdfarjunhassan8
 
The following table is a summary of randomly chosen student evaluati.pdf
The following table is a summary of randomly chosen student evaluati.pdfThe following table is a summary of randomly chosen student evaluati.pdf
The following table is a summary of randomly chosen student evaluati.pdfarjunhassan8
 
A female carrier of Tay-Sachs wants to have a child with a male carri.pdf
A female carrier of Tay-Sachs wants to have a child with a male carri.pdfA female carrier of Tay-Sachs wants to have a child with a male carri.pdf
A female carrier of Tay-Sachs wants to have a child with a male carri.pdfarjunhassan8
 
So I dont understand explicit equations. Whats the formula and how.pdf
So I dont understand explicit equations. Whats the formula and how.pdfSo I dont understand explicit equations. Whats the formula and how.pdf
So I dont understand explicit equations. Whats the formula and how.pdfarjunhassan8
 
Sapling Learning Select the statements that explain why duplication i.pdf
Sapling Learning Select the statements that explain why duplication i.pdfSapling Learning Select the statements that explain why duplication i.pdf
Sapling Learning Select the statements that explain why duplication i.pdfarjunhassan8
 
Question 1 Humans have affected different organism populations in wh.pdf
Question 1 Humans have affected different organism populations in wh.pdfQuestion 1 Humans have affected different organism populations in wh.pdf
Question 1 Humans have affected different organism populations in wh.pdfarjunhassan8
 
Problem 4. The ancient Romans employed a volcanic ash called pozzolan.pdf
Problem 4. The ancient Romans employed a volcanic ash called pozzolan.pdfProblem 4. The ancient Romans employed a volcanic ash called pozzolan.pdf
Problem 4. The ancient Romans employed a volcanic ash called pozzolan.pdfarjunhassan8
 
presence of protected, multicellular embryoshaploid (n) gametophytes a.pdf
presence of protected, multicellular embryoshaploid (n) gametophytes a.pdfpresence of protected, multicellular embryoshaploid (n) gametophytes a.pdf
presence of protected, multicellular embryoshaploid (n) gametophytes a.pdfarjunhassan8
 
Plants and ChromatographySeparation of Photosynthetic Pigments by .pdf
Plants and ChromatographySeparation of Photosynthetic Pigments by .pdfPlants and ChromatographySeparation of Photosynthetic Pigments by .pdf
Plants and ChromatographySeparation of Photosynthetic Pigments by .pdfarjunhassan8
 
On saturday morning, Pam walked for 2 hours and then ran for 30 minu.pdf
On saturday morning, Pam walked for 2 hours and then ran for 30 minu.pdfOn saturday morning, Pam walked for 2 hours and then ran for 30 minu.pdf
On saturday morning, Pam walked for 2 hours and then ran for 30 minu.pdfarjunhassan8
 
1)Why have concerns over pollution become so important for managemen.pdf
1)Why have concerns over pollution become so important for managemen.pdf1)Why have concerns over pollution become so important for managemen.pdf
1)Why have concerns over pollution become so important for managemen.pdfarjunhassan8
 
history adaptaion of gorials. what is their parental care, please ci.pdf
history adaptaion of gorials. what is their parental care, please ci.pdfhistory adaptaion of gorials. what is their parental care, please ci.pdf
history adaptaion of gorials. what is their parental care, please ci.pdfarjunhassan8
 
How are devices called that were on the market before FDA started reg.pdf
How are devices called that were on the market before FDA started reg.pdfHow are devices called that were on the market before FDA started reg.pdf
How are devices called that were on the market before FDA started reg.pdfarjunhassan8
 

More from arjunhassan8 (20)

Which of the following is NOT a rationale for using mRNA intermed.pdf
Which of the following is NOT a rationale for using mRNA intermed.pdfWhich of the following is NOT a rationale for using mRNA intermed.pdf
Which of the following is NOT a rationale for using mRNA intermed.pdf
 
Which elements are in series and which are in parallel in Figure P1.3.pdf
Which elements are in series and which are in parallel in Figure P1.3.pdfWhich elements are in series and which are in parallel in Figure P1.3.pdf
Which elements are in series and which are in parallel in Figure P1.3.pdf
 
What domain is horizontal gene transfer most common within Multiple .pdf
What domain is horizontal gene transfer most common within Multiple .pdfWhat domain is horizontal gene transfer most common within Multiple .pdf
What domain is horizontal gene transfer most common within Multiple .pdf
 
This problem is based on the B92 method of quantum key distri.pdf
This problem is based on the B92 method of quantum key distri.pdfThis problem is based on the B92 method of quantum key distri.pdf
This problem is based on the B92 method of quantum key distri.pdf
 
The _ operator can be used to determine a variable address The variab.pdf
The _ operator can be used to determine a variable address The variab.pdfThe _ operator can be used to determine a variable address The variab.pdf
The _ operator can be used to determine a variable address The variab.pdf
 
The main difference between passive and active transport is the spec.pdf
The main difference between passive and active transport is  the spec.pdfThe main difference between passive and active transport is  the spec.pdf
The main difference between passive and active transport is the spec.pdf
 
The opposite movement of supination is ___. Pronation flexion exte.pdf
The opposite movement of supination is ___.  Pronation  flexion  exte.pdfThe opposite movement of supination is ___.  Pronation  flexion  exte.pdf
The opposite movement of supination is ___. Pronation flexion exte.pdf
 
The latter or final stages of an RNA based heriditary world were lik.pdf
The latter or final stages of an RNA based heriditary world were lik.pdfThe latter or final stages of an RNA based heriditary world were lik.pdf
The latter or final stages of an RNA based heriditary world were lik.pdf
 
The following table is a summary of randomly chosen student evaluati.pdf
The following table is a summary of randomly chosen student evaluati.pdfThe following table is a summary of randomly chosen student evaluati.pdf
The following table is a summary of randomly chosen student evaluati.pdf
 
A female carrier of Tay-Sachs wants to have a child with a male carri.pdf
A female carrier of Tay-Sachs wants to have a child with a male carri.pdfA female carrier of Tay-Sachs wants to have a child with a male carri.pdf
A female carrier of Tay-Sachs wants to have a child with a male carri.pdf
 
So I dont understand explicit equations. Whats the formula and how.pdf
So I dont understand explicit equations. Whats the formula and how.pdfSo I dont understand explicit equations. Whats the formula and how.pdf
So I dont understand explicit equations. Whats the formula and how.pdf
 
Sapling Learning Select the statements that explain why duplication i.pdf
Sapling Learning Select the statements that explain why duplication i.pdfSapling Learning Select the statements that explain why duplication i.pdf
Sapling Learning Select the statements that explain why duplication i.pdf
 
Question 1 Humans have affected different organism populations in wh.pdf
Question 1 Humans have affected different organism populations in wh.pdfQuestion 1 Humans have affected different organism populations in wh.pdf
Question 1 Humans have affected different organism populations in wh.pdf
 
Problem 4. The ancient Romans employed a volcanic ash called pozzolan.pdf
Problem 4. The ancient Romans employed a volcanic ash called pozzolan.pdfProblem 4. The ancient Romans employed a volcanic ash called pozzolan.pdf
Problem 4. The ancient Romans employed a volcanic ash called pozzolan.pdf
 
presence of protected, multicellular embryoshaploid (n) gametophytes a.pdf
presence of protected, multicellular embryoshaploid (n) gametophytes a.pdfpresence of protected, multicellular embryoshaploid (n) gametophytes a.pdf
presence of protected, multicellular embryoshaploid (n) gametophytes a.pdf
 
Plants and ChromatographySeparation of Photosynthetic Pigments by .pdf
Plants and ChromatographySeparation of Photosynthetic Pigments by .pdfPlants and ChromatographySeparation of Photosynthetic Pigments by .pdf
Plants and ChromatographySeparation of Photosynthetic Pigments by .pdf
 
On saturday morning, Pam walked for 2 hours and then ran for 30 minu.pdf
On saturday morning, Pam walked for 2 hours and then ran for 30 minu.pdfOn saturday morning, Pam walked for 2 hours and then ran for 30 minu.pdf
On saturday morning, Pam walked for 2 hours and then ran for 30 minu.pdf
 
1)Why have concerns over pollution become so important for managemen.pdf
1)Why have concerns over pollution become so important for managemen.pdf1)Why have concerns over pollution become so important for managemen.pdf
1)Why have concerns over pollution become so important for managemen.pdf
 
history adaptaion of gorials. what is their parental care, please ci.pdf
history adaptaion of gorials. what is their parental care, please ci.pdfhistory adaptaion of gorials. what is their parental care, please ci.pdf
history adaptaion of gorials. what is their parental care, please ci.pdf
 
How are devices called that were on the market before FDA started reg.pdf
How are devices called that were on the market before FDA started reg.pdfHow are devices called that were on the market before FDA started reg.pdf
How are devices called that were on the market before FDA started reg.pdf
 

Recently uploaded

How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 

Recently uploaded (20)

How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 

Write the code segments to create a monitor that has the same behavi.pdf

  • 1. Write the code segments to create a monitor that has the same behavior as a semaphore. Monitor semaphore { //initialization // synchronization condition variable // methods wait ( ) signal ( ) } Solution I assume the code is to be written in Java as no language is specified. The solution is below: public class Monitor_Semaphore { private int count; //initialize public Semaphore (int init) { count = init; } //signal synchronized public void S() { count++; notify(); } //wait synchronized public void W() throws InterruptedException { while (count == 0) wait(); count--; }