草庐IT

named_mutex

全部标签

c++ - 将 std::mutex 用于由 boost::asio 管理的线程池

以某种方式跟进了thisquestion.我只是想知道在由boost::asio:io_service处理的函数中使用std::mutex是否可以?股的使用有点不切实际。根据我在boostreference中的发现我会说没关系。因为它指出Asynchronouscompletionhandlerswillonlybecalledfromthreadsthatarecurrentlycallingio_service::run().所以boost创建的其他线程不应该干涉。我做对了吗? 最佳答案 正如其他人所指出的,std::mutex

c++ - boost mutex, condition, scoped_lock ,我在这里用错了吗?

classMyClass{public:voidPushMessage(MyMessagem)//Thread1callsthis{boost::mutex::scoped_locklock(mMutex);mQueue.push_back(m);mCondition.notify_one();}MyMessagePopMessage(){boost::mutex::scoped_locklock(mMutex);while(mQueue.empty())mCondition.wait(lock);MyMessagemessage=mQueue.front();mQueue.pop_f

c++ - gtkmm 的 g_signal_emit 或 g_signal_emit_by_name 版本是什么?

我在我的程序后台运行一个超时函数,我试图从Gtk::Button发出一个删除事件信号,这是我的构造函数中的代码片段://Glib::SignalProxy1m_deleteSlot;//m_deleteSlot=signal_delete_event().connect(sigc::mem_fun(*this,&AlarmUI::my_delete_event));m_timeout_connection=Glib::signal_timeout().connect_seconds(sigc::mem_fun(*this,&AlarmUI::cb_my_tick),1);`现在,方法:

c++ - 振奋 spirit : What type names should be used for the built in terminals?

我正在重构一个类型系统(类型模型),它使用spirit进行字符串序列化。我正在使用类型特征的编译时建模构造。templatetype_traits{typedefboost::spirit::qi::int_parserstring_parser;}templatetype_traits{typedefboost::spirit::ascii::stringstring_parser;}在这个例子中,我展示了原始解析器,但我希望也加入规则。int4类型有效,但这是因为(home/qi/numeric/int.hpp+27):namespacetag{templatestructint_

c++ - 将 boost::mutex 与 MFC 线程 (AfxBeginThread) 一起使用?

当您不使用boost::thread而是通过AfxBeginThread使用MFC线程功能时,您能否使用boost::mutex库来保护代码的关键部分?如果是这样,这样做有什么问题吗? 最佳答案 一个(真实的)线程是一个(真实的)线程。Boost对线程是直接创建(WindowsAPI)还是通过Boost创建没有特殊假设。简答:没问题。 关于c++-将boost::mutex与MFC线程(AfxBeginThread)一起使用?,我们在StackOverflow上找到一个类似的问题:

python - c++中python "type(<name>, <bases>, <dict>)"的等价物是什么?

好吧,我正在将python3.3嵌入到C++应用程序中。我希望在C++端动态创建一个Python类,就像我在Python中执行以下操作一样:my_type=type("MyType",(object,),dict())我知道我总是可以导入“builtins”模块,但我一般会尽量避免在C++端导入。谢谢! 最佳答案 以下似乎工作得很好:PyObject*type(constchar*name,boost::python::tuplebases,boost::python::dictdict){returnPyType_Type.tp_

c++ - 编译错误 : `‘error_category’ does not name a type` with g++ 6. 3.0

我尝试编译这个C++/Python库https://bitbucket.org/fluiddyn/fluidfft如果安装了mpi4py,它运行良好。如果没有安装mpi4py,不使用MPI的代码无法编译。编译Cython文件时出现错误。错误很长,开始于:Infileincludedfrom/usr/include/c++/6/bits/ios_base.h:46:0,from/usr/include/c++/6/ios:42,from/usr/include/c++/6/ostream:38,from/usr/include/c++/6/iostream:39,fromsrc_cpp/

c++ - 什么时候 std::shared_timed_mutex 比 std::mutex 慢,什么时候(不)使用它?

我正在尝试使用this在C++中实现多线程LRU缓存文章作为提示或灵感。它适用于Go,但所需的概念或多或少也存在于C++中。本文建议在散列表和链表周围使用带有共享互斥锁的细粒度锁定。所以我打算用std::unordered_map写一个缓存,std::list并使用std::shared_timed_mutex锁定.我的用例包括几个线程(4-8)使用此缓存作为拼写错误的单词和相应可能的更正的存储。缓存的大小约为10000-100000个项目。但是我在几个地方读到,使用共享互斥锁而不是普通互斥锁几乎没有意义,而且速度更慢,尽管我找不到一些带有数字的真实基准或至少在何时使用和何时不使用的模

c++ - boost named_semaphore 示例?

我没能找到一个很好的例子来展示如何使用boost::interprocess::named_semaphore(甚至在Boost网站上也没有)。我可以看到一些关于interprocess_semaphore的东西,但它们似乎完全不同,我不知道为一个显示的内容是否也适用于另一个。任何人都可以给我一些指向此类示例/tutorials/documentation的链接吗?谢谢。 最佳答案 interprocess_semaphore和named_semaphore之间的主要区别在于interprocess_semaphore是通过使用共享

c++ - Qt错误: 'const class QString' has no member named 'toStdString'

我收到此错误error:'constclassQString'hasnomembernamed'toStdString'虽然QString有它。(link).代码std::stringMessage::toStdString()const{returnm_string.toStdString();} 最佳答案 直接从这里复制答案:HowtoconvertQStringtostd::string?QStringqs;//EitherthisifyouuseUTF-8anywherestd::stringutf8_text=qs.toU