mutable boost::mutex 是否可以将锁定和等待功能分开?
所以我有像 read
这样的函数,可以从多个线程同时调用。而且我还有一个写入函数,需要锁定所有读取函数。在哪里可以获得创建此类架构的示例?
我知道我们可以:
mutable boost::mutex the_read_mutex;
mutable boost::mutex the_write_mutex;
和:
void write()
{
// make all new readers wait and wait for all other currently running read threads();
}
void read()
{
// do not make all new readers wait, and wait for all currently running write thread()
}
那么如何做这样的事情呢?
So I have functions like read
that can be called at the same time from multiple threads. but also I have a function to write
that needs to lock all that read
functions. Where to get example of creating such archetecture?
I get that we can have:
mutable boost::mutex the_read_mutex;
mutable boost::mutex the_write_mutex;
and:
void write()
{
// make all new readers wait and wait for all other currently running read threads();
}
void read()
{
// do not make all new readers wait, and wait for all currently running write thread()
}
So how to do such thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
要了解有关 boost-locks 的更多信息: Boost 线程同步机制
要了解您正在处理的问题的类别:Wikipedia 链接到Reader-WriterLock
要了解有关 POSIX 读写锁的更多信息,它可以通过非常简单的语法直接为您提供读写锁:POSIX 读写锁
You can use
To know more about boost-locks : Boost thread sync mechanisms
To know about the class of the problem you are dealing with : Wikpedia Link to Reader-WriterLock
To know more about POSIX reader-writer lock, which directly gives you reader write lock with much simple syntax : POSIX reader-witer locks