0
我正在使用watchdir将服务器添加到内部集合的服务器上工作。将boost :: bind与包含boost :: mutex的类一起使用
this->watchDirThread = new boost::thread(boost::bind(&Filesystem::watchDirThreadLoop,
this,
this->watchDir,
fileFoundCallback));
的fileFoundCallback
参数也通过boost::bind
创建:该watchdir由被这样创建一个线程定期浏览
boost::bind(&Collection::addFile, this->collection, _1)
我想用互斥来保护我的收藏从并发访问但我的问题是boost::mutex
类是不可复制的,因此Collection
类中不能有互斥体,因为boost::bind
需要可复制参数。
我不喜欢静态互斥体的想法,因为它在语义上是错误的,因为互斥体的作用是阻止我的集合在被修改时被读取。
我能做些什么来解决这个问题?