草庐IT

scoped-lock

全部标签

c++ - 是否有用于 boost::interprocess 的 'upgrade_to_unique_lock'?

我正在寻找在偏向编写器读取器/编写器模型中的两个(或多个)进程之间有效共享数据block的最佳方法。我当前的测试是使用boost::interprocess。我已经创建了一些managed_shared_memory并试图通过使用存储在共享内存中的进程间互斥来锁定对数据block的访问。但是,即使在读取器上使用sharable_lock并在写入器上使用upgradable_lock时,客户端在写入操作期间将读取碎片值而不是阻塞。在单个进程中的线程之间进行类似的读写器设置时,我使用upgrade_to_unique_lock来解决这个问题。但是,我还没有找到它的boost::interp

c++ - 为什么在单例实现中清除 boost::scoped_ptr

我使用boost::scoped_ptr实现了一个简单的单例:templateclassSingleton:publicboost::noncopyable{public:staticT&instance(){boost::call_once(init,flag);return*t;}staticvoidinit(){t.reset(newT());}private:staticboost::scoped_ptrt;staticboost::once_flagflag;};templateboost::scoped_ptrSingleton::t(0);templateboost::o

c++ - boost::lock 在 boost 1.53 中无法编译

我正在编译一个项目。它有以下几行:boost::mutex::scoped_lockml(m_meta_mut,boost::defer_lock);boost::mutex::scoped_locktl(m_tables_mut,boost::defer_lock);boost::lock(ml,tl);我在第三行收到lockisnotamemberofboost。我用的是boost1.53(项目推荐1.49)问题是什么 最佳答案 将我的评论变成更完整的答案。boost::lock()功能是definedinboost/threa

c++ - "static functions with block scope are illegal"错误取决于初始化样式?

我有一个类Library,其中包含一个结构Transaction,该结构有一个类型为Patron的成员变量。classPatron{public:Patron(){}};classLibrary{public:structTransaction{Patronp;Transaction(Patronpp):p(pp){}Transaction();};};对于Transaction的默认构造函数,我有一个函数default_transaction()返回对静态对象的const引用,正如Stroustrup在“编程-原则和实践”中所推荐的使用C++”(第324页);推理:避免在构造函数代码

c++ - Reader Writer Lock 支持低优先级的写者

我正在尝试寻找(或实现)支持低优先级写入器的读取器/写入器锁,但未能成功研究任何现有解决方案。我所说的低优先级写入器的意思是:“将让位给即将到来的读者或普通写入器”。如果有持续不断的读者流,肯定会导致饥饿,但这可以通过定时锁变体(“尝试定时低优先级写入器锁”,然后在超时时切换到正常锁)或通过更改来解决读取器的发布方式(可能会定期暂停读取一小段时间)。如果有任何文献描述这些东西,我还没有找到。如果有利用常规锁的已知(正确!)解决方案,我将不胜感激。 最佳答案 我不知道有什么100%像你的建议,但有一些现有的接口(interface)很

c++ - 错误 : ‘Class’ was not declared in this scope

请问,如何在另一个类中定义类。在下面的代码中。我尝试以#define"CCompField.h"的方式定义它,但它不起作用。:(。我认为这是非常常见的编程问题,可能在互联网上已经解决了100000次,但我不知道如何找到它。感谢您的帮助。#ifndefCNEWGAME_H#defineCNEWGAME_HclassCNewGame{public:CNewGame();~CNewGame();voidBeginnerGame();voidIntermediateGame();voidAdviceGame();voidHowToPlay();voidNetGame(intmode);intM

c++ - 谷歌测试 Gtest.cc :812: error: 'gettimeofday' was not declared in this scope

我正在尝试通过命令行通过MinGW编译Google测试,但是当我尝试使用命令进行编译时gcc-ID:\gtest-ID:\gtest\include-ID:\gtest\include\gtestsrc\gtest_main.ccsrc\gtest-all.cc它抛出错误Gtest.cc:812:错误:'gettimeofday'未在此范围内声明我通过VisualStudio成功编译,所以我猜这不是代码的错误。还有其他人遇到过这个问题并且知道解决方案吗? 最佳答案 and是两个不同的包含

c++ - 错误 : 'object' was not declared in this scope

我是C++的新手,正在尝试制作大富翁游戏。不幸的是,它仍然显示两个类之间的声明错误。我已经尝试了所有方法,但真的不知道问题出在哪里。错误:“玩家”未在此范围内声明。引擎.h#ifndefENGINE_H#defineENGINE_H#include"Player.h"#includeusingnamespacestd;classEngine{public:Engine();//methodthatstartswithgame,takerandomnumberforgettingnumberofplayers,setplayerstovectorvoidplay();//methodwh

c++ - 是否有任何惯用的显式使用 mutex::lock() 或 unlock()?

推荐的使用方式mutex用于锁定代码的关键区域是通过RAII,即mutex_typemutex;{//startofcriticalregionstd::lock_guardlock(mutex);//firststatementincriticalregion//...docriticalstuff,maythrowanexception}//endofcriticalregion这样当在临界区内抛出异常时,互斥量仍将被解锁(由std::lock_guard的析构函数)。然而,这样的成员mutex::lock()和mutex::unlock()永远不会被用户代码显式调用。Qmutex

c++ - 当非限定名称查找涉及 using-directives 时 [basic.scope.hiding]p2 的解释

在c++中有两种隐藏的名字:1)普通名称隐藏:[basic.scope.hiding]p1(http://eel.is/c++draft/basic.scope.hiding#1):Anamecanbehiddenbyanexplicitdeclarationofthatsamenameinanesteddeclarativeregionorderivedclass([class.member.lookup]).2)隐藏在[basic.scope.hiding]p2(http://eel.is/c++draft/basic.scope.hiding#2)中的特殊名称类型:Aclassn