You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
804 B
39 lines
804 B
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading;
|
|
|
|
namespace Sync_Ueb02_Latch
|
|
{
|
|
class Latch : ISynch
|
|
{
|
|
private ManualResetEvent waitHandle = new(false);
|
|
private static uint countAquired = 0;
|
|
private static object syncLock = new();
|
|
|
|
public void Acquire()
|
|
{
|
|
lock (syncLock)
|
|
{
|
|
countAquired++;
|
|
}
|
|
this.waitHandle.WaitOne();
|
|
}
|
|
|
|
public uint GetAmountOfAquires()
|
|
{
|
|
uint readCount = 0;
|
|
lock(syncLock)
|
|
{
|
|
readCount = countAquired;
|
|
}
|
|
return readCount;
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
this.waitHandle.Set();
|
|
}
|
|
}
|
|
|
|
}
|
|
|