信号量控制的资源 - 什么是干净关闭序列/模式
如果我用信号量控制一个资源池,该资源池的干净关闭顺序是什么?
class ResourcePool
{
Semaphore resourceSemaphore;
Stack<ResourceClass> resources;
public ResourcePool()
{
resources ... // Init some Resources in the stack
resourceSemaphore= new Semaphore(resources.Count,resources.Count);
}
public void ResourceTask()
{
resourceSemaphore.WaitOne();
ResourceClasscurrent = null;
try
{
current = resources.Pop();
current.Task();
}
finally
{
if( current != null )
resources.Push(current);
resourceSemaphore.Release();
}
}
}
如何为该池实现干净的关闭顺序?也许资源使用 IDisposable,这最终应该发挥作用。
If i control a pool of resources with a semaphore, what is the clean shutdown sequence for this resource pool?
class ResourcePool
{
Semaphore resourceSemaphore;
Stack<ResourceClass> resources;
public ResourcePool()
{
resources ... // Init some Resources in the stack
resourceSemaphore= new Semaphore(resources.Count,resources.Count);
}
public void ResourceTask()
{
resourceSemaphore.WaitOne();
ResourceClasscurrent = null;
try
{
current = resources.Pop();
current.Task();
}
finally
{
if( current != null )
resources.Push(current);
resourceSemaphore.Release();
}
}
}
How to implement a clean shutdown sequence for this pool? Maybe the resources use IDisposable, this should eventually come into play.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望对CLR 中的线程管理有所帮助
Hope that helps Thread Management In The CLR