top button
Flag Notify
Site Registration

The following code implements the semaphore using C#, find is there any weekness or bug.

0 votes
307 views
public class Semaphore
{
private object _mutex = new object;
private int _currAvail;
public Semaphore(int capacity)
{
_currAvail = capacity;
}
public void Wait()
{
lock(_mutex)
{
if ( currAvail == 0) Monitor.Wait(_mutex);
_currAvail --;
}
}
public void Signal()
{
lock(_mutex)
{
_currAvail ++;
Monitor.Pulse(_mutex);
}
}
}
posted Apr 2, 2019 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+2 votes

Develop a C# Windows Form Application that allows users to do all of the following.
Read a List of patient's information from a text file (*.txt), the input text file is selected from the Open File Dialog.
Your program should accept any text file with the following format:
a. The file contains columns with Basic information about patients.
b. Columns may be separated by spaces and/or tabs.
c. The first line in the file is the column header.
d. After the header, each line represents a Patient (name, address, phone#, Bdate, gander ,wheight, height and blood type).
e. Successfully imported patients are displayed on a data grid view in a second form and added to a patient list.

  1. The user will be able to display on The Grid view :
    a) Female patients.
    b) Patients with age<45 year. c) Save Over weighted patients on a text file .  Note: To find over weighted patients you have to calculate the BMI value. BMI=Weight/ (Height*Height). If BMI <18.5 >>>>> under weighted.
    18.5<=BMI<=25 >>>>>>>Normal.
    BMI>25 >>>>>>>>>>>> Over Weighted.
0 votes

How to implement an Object Pool in C#.NET.

...