Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Countdown
- {
- object _locker = new object ();
- int _value;
- public Countdown() { }
- public Countdown (int initialCount) { _value = initialCount; }
- public void Signal() { AddCount (-1); }
- public void AddCount (int amount)
- {
- lock (_locker)
- {
- _value += amount;
- if (_value <= 0) Monitor.PulseAll (_locker);
- }
- }
- public void Wait()
- {
- lock (_locker)
- while (_value > 0)
- Monitor.Wait (_locker);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment