多个请求者的设计模式,其中只有一个请求者导致资源被获取,并且当资源可用时所有请求者都会收到通知?
多个线程可以向资源请求但只有一个成功的设计模式是什么?当资源可用时,所有其他请求者都会收到通知。
例如,两个或多个线程请求通过网络获取的资源文件。第一个线程会阻塞其他两个线程。第一个线程生成单个请求,然后等待资源变得可用,就像其他两个等待线程一样。
当我说等待时,它们并不是真正等待阻塞,而是检查变量或其他东西,因为这已经是线程池的一部分,因此其他线程可以执行其他工作。
这种设计模式叫什么?
What would be a suitable design pattern where multiple threads could request from a resource, but only one of them succeeds. All the other requesters are notified when the resource is available.
For example, two or more threads requests a resource file which is obtained over the network. The first one in blocks the other two threads. The first thread generates a single request and then waits for the resource to become available just like the other two waiting threads.
When I say waiting, they don't really wait blocking, they check a variable or something because this is already part of a thread-pool so those other threads can do other work.
What is that design pattern called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的意思是
Mutex.TryLock()
吗?免责声明:在 Windows/.NET 术语中;其他平台和语言中的名称和语法可能有所不同。
Do you mean
Mutex.TryLock()
?Disclaimer: In Windows/.NET terminology; names and syntax may differ in other platforms and languages.
您大致有三种选择:
我非常喜欢第二种选择,但选择实际上取决于您的特定要求。
You have roughly three choices:
I quite like the second option, but the choice really depends on your particular requirements.