C# 选择哪种线程模式
假设我们有一个接口方法 A,它是可重入的,并且对于方法中的每个条目,当前线程都应等待,直到专门针对 this 线程发生事件:
void interfaceMethodA()
{
doSomething();
waitHandle.WaitOne();
}
现在,将有 set() 调用对于waitHandle,这样该方法就会退出。但是这些 set() 调用必须释放(可能的)线程队列中的特定线程,而不一定是第一个线程。这种模式的最佳实践是什么,也许是 wait() 和pulse() 与线程 ID 向量的结合?对我来说,这似乎有点乱……
提前致谢,Juergen
Say we have an interface method A, which is reentrant capable and for every entry in the method the current thread shall wait until an event occurs specifically for this thread:
void interfaceMethodA()
{
doSomething();
waitHandle.WaitOne();
}
Now, there will be set()-calls for the waitHandle, so that the method will be exited. But those set() calls must release a specific thread of the (possible) thread queue and not neccessarily the first one. What is a best practise for this pattern, maybe wait() and pulse() in combination with a thread id vector? To me this seems a bit like a mess...
Thanks in advance, Juergen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 ThreadLocal
You could use a
ThreadLocal<WaitHandle>