草庐IT

Variable_init

全部标签

c++ - notify_all 崩溃后直接删除 std::condition_variable_any

我有一部分代码,其中一个线程调用如下内容:cond->notify_all();deletecond;与std::condition_variable_anycond;Afaik,这应该有效,因为Ishouldbeallowedtodeletetheconditionvariable,assoonasInotifiedallthreadswaitingonit,他们不必从wait调用中恢复。在Windows上,这有时会因错误而崩溃:mutexdestroyedwhilebusy打印到标准输出在Linux上,使用clang3.5这工作得很好,在Windows上我使用VisualStudi

c++ - D3D11 : variable number of lights in HLSL

我正在使用C++和Direct3D11开发游戏引擎,现在我想向场景中添加可变数量的灯光。到目前为止,我设法添加和渲染了一些已知的并在着色器程序中编码的简单灯光。在shader.fx中:staticconstintLightsCount=4;structNF3D_LIGHT{//Members...};cbufferLight:register(b5){NF3D_LIGHTlight[LightsCount];};...//Andthepixelshaderfunction:float4PS(PS_INPUTinput):SV_Target{for(inti=0;i这很好用。但如果我尝试

c++ - 我们应该如何在函数中使用带有 std::accumulate 的模板来通过考虑模板而不是 "init"来返回正确的类型

std::accumulate的返回类型取决于“init”,即如果它是整数,它将返回整数,如果是double,它将返回double。我有一个像这样求和的模板函数:Tmean(std::vectorvector){Tsum=std::accumulate(vector.begin(),vector.end(),X);}我应该用什么代替X? 最佳答案 您可以只使用T{},它是默认构造的T。例如Tsum=std::accumulate(vector.begin(),vector.end(),T{});如果你需要用一些初始值来初始化它,你可

c++ - boost::interprocess : cout a string variable when iterating through a map that references an object from a struct

我正在使用boost::interprocess在进程之间共享对象。我有两个文件,一个生成结构对象并将该对象传递到具有int索引的映射中的“server.cpp”;和一个“client.cpp”文件,它检索内存数据并遍历数据,输出到控制台。结构看起来像这样:structmydatao{stringMY_STRING;intMY_INT;};和对象:mydatao;o.MY_STRING="hello";o.MY_INT=45;服务器和客户端都能正确编译。但是出于某种原因,如果我尝试访问客户端中的字符串而不是float或整数,客户端可执行文件会抛出段错误。例如下面的second.MY_I

C++ 11 : Mutex & Condition Variable Cannot be Copied

我是C++11的新手,正在使用线程。我遇到了一个无法复制互斥锁和条件变量对象的场景。代码是这样的....classproducer{public:producer(mutexm,condition_variablecv){mut=m;//ERRORcvar=cv;//ERROR}private:mutexmut;condition_variablecvar;}尝试在构造函数中复制变量时出现错误。似乎复制构造函数设置为deleteformutex和cv。有办法克服吗?我想要一个生产者和消费者类,然后从ma​​in函数传递互斥量和cv。所以基本上来自main函数的调用应该是这样的.....

c++ - std::condition_variable::notify_all() 保证

假设一个条件变量上有N个等待线程(读者),它们被另一个线程(生产者)通知。现在,所有N个读者都将尝试拥有他们引用的unique_lock,一次一个。现在假设生产者出于某些原因想要再次锁定同一个unique_lock,甚至在任何被唤醒的读者开始拥有锁之前。按照标准,只有在所有被通知的读者都开始锁定步骤后,生产者才能成功(尝试)进入其临界区吗? 最佳答案 除了§1.10第2段中给出的相当模糊的调度之外,没有关于调度的保证:Implementationsshouldensurethatallunblockedthreadseventual

c++ - shared_future<void> 是 condition_variable 的合法替代品吗?

Josuttis指出[“标准库”,第2版,第1003页]:Futuresallowyoutoblockuntildatabyanotherthreadisprovidedoranotherthreadisdone.However,afuturecanpassdatafromonethreadtoanotheronlyonce.Infact,afuture'smajorpurposeistodealwithreturnvaluesorexceptionsofthreads.另一方面,shared_future可以被多个线程使用,以识别另一个线程何时完成了它的工作。另外,一般来说,高级并发

c++ - 为什么condition_variable在producer-consumer中等待锁呢? C++

看下面经典的生产者消费者代码:intmain(){std::queueproduced_nums;std::mutexm;std::condition_variablecond_var;booldone=false;boolnotified=false;std::threadproducer([&](){for(inti=0;ilock(m);std::coutlock(m);while(!done){while(!notified){//looptoavoidspuriouswakeupscond_var.wait(lock);}while(!produced_nums.empty(

c++ - 为了使用 Glib::wrap,必须 Glib::init()'ed 什么?

所以我正在尝试使用GtkSourceViewmm在C++中使用GtkSourceView,其文档和支持水平给我的印象是很长一段时间没有仔细研究它。但我始终是一个乐观主义者:)我正在尝试添加SourceView使用一些类似于以下的代码:Glib::RefPtrsource_language_manager=gtksourceview::SourceLanguageManager::create();Glib::RefPtrsource_language=Glib::wrap(gtk_source_language_manager_guess_language(source_languag

c++ - condition_variable_any 与 recursive_mutex 一起使用时的行为?

当condition_variable_any与recursive_mutex一起使用时,recursive_mutex是否通常可从其他线程获取,同时condition_variable_any::wait正在等待?我对Boost和C++11实现都很感兴趣。这是我主要关心的用例:voidbar();boost::recursive_mutexmutex;boost::condition_variable_anycondvar;voidfoo(){boost::lock_guardlock(mutex);//Ownershiplevelisnowonebar();}voidbar(){b