/// <summary> /// 构造一个初始为给定集合的实例。 /// </summary> public Semaphore(IEnumerable <T> collection) { foreach (var data in collection) { Data.AddLast(data); SemaphoreCount.Release(1); } }
/// <summary> /// 产生一个对象。 /// </summary> /// <exception cref="Exception"></exception> /// <returns></returns> public void Release(T data) { lock (Data) { Data.AddLast(data); } SemaphoreCount.Release(); }
/// <summary> /// 产生一组对象。 /// </summary> /// <exception cref="Exception"></exception> /// <returns></returns> public void Release(IEnumerable <T> collection) { int count = 0; lock (Data) { foreach (var data in collection) { Data.AddLast(data); count++; } } SemaphoreCount.Release(count); }
/// <summary> /// 构造一个初始为给定元素的实例。 /// </summary> public Semaphore(T data) { Data.AddLast(data); SemaphoreCount.Release(1); }