草庐IT

thread-specific-storage

全部标签

c++ - 带有 C++ 模板的虚假 "use of local variable with automatic storage from containing function"?

以下代码无法在g++7.2.0中编译templateclassRequest{intcontent=0;public:friendvoidsetContent(inti,void*voidptr){Request*ptr=(Request*)voidptr;ptr->content=i;}intgetContent(){returncontent;}};intmain(){Requestreq;setContent(4,&req);returnreq.getContent();}有错误test.cpp:Ininstantiationof‘voidsetContent(int,void*

java - 对象: no thread state can be involved,的序列化对吗?

我正在认真研究将正在执行的程序的状态存储到磁盘并再次将其取回的基本原理。在我们当前的设计中,每个对象(这是一个带有函数指针列表的C级东西,一种低级的自制面向对象——这样做有很好的理由)将是调用以将其显式状态导出为可写和可恢复的格式。使这项工作有效的关键属性是与对象相关的所有状态确实封装在对象数据结构中。还有其他解决方案,您可以使用Activity对象,其中有一个用户级线程附加到某些对象。因此,程序计数器、寄存器内容和堆栈内容突然成为程序状态的一部分。据我所知,没有什么好的方法可以在任意时间点将此类内容序列化到磁盘。线程必须将自己停在某个特殊状态,其中程序计数器等不代表任何内容,因此基本

C++ 模板 : Partial Template Specifications and Friend Classes

是否有可能以某种方式使部分模板规范成为友元类?IE。考虑你有以下模板类templateclassX{Tt;};现在你有了部分特化,例如,指针templateclassX{T*t;};我想要完成的是每一个可能的X是X的好友类对于任何S.IE。X应该是X的friend.当然,我想到了X中的常用模板友元声明:templateclassX{templatefriendclassX;}但是,这不会编译,g++告诉我:test4.cpp:34:15:错误:'templateclassX的特化'必须出现在命名空间范围内test4.cpp:34:21:错误:部分特化'X'声明'friend'这根本不可

c++ - 将 C++11 std::thread 移植到 boost::thread 编译问题

我正在尝试使用boost::thread将C++11std::thread代码移植到VC9(VS2008)。下面的“等效”C++11代码在msvc12上编译良好:#include#include#include#include#includevoidthFun(inti){std::coutworkers;for(inti=0;i我想使用msvc9编译器和Boost1.55将代码移植到C++03。如何解决以下编译错误:#include#include#include#include#includevoidthFun(inti){std::coutworkers;for(inti=0;i

c++ - Eclipse 内容辅助无法识别 std::thread,但可以正确编译

我正在运行Ubuntu14.04。我重现的步骤:创建一个新的C++项目(新建->C++->HelloWorld项目),我将其命名为TestStdThread将主文件中的代码更改为:#include#includeintmain(){std::cout转到TestStdThread->Properties->C/C++Build->Settings->GCCC++Compiler,并将Command选项从g++更改为g++-std=c++11转到TestStdThread->Properties->C/C++Build->Settings->GCCC++Compiler->Include

c++ - std::this_thread::sleep_for() 可以有虚假唤醒吗?

请注意,这不是关于std::condition_variable::wait_for()的问题。我知道这可能会虚假唤醒。我的程序的行为表明这个问题的答案是肯定的,但是STL文档对于condition_variable的情况非常清楚。至少在cppreference.com,this_thread的正确答案似乎是否。编译器是gcc4.8.1,以防这是一个缺陷。 最佳答案 C++标准的相关部分(第[thread.thread.this]/7-9段)没有提及任何关于std::this_thread::sleep_for的虚假唤醒,不像例如对

c++ - 我可以将 Thread Sanitizer 用于 OpenMP 程序吗?

考虑以下示例:#includeintmain(){inti=0;#pragmaompparallel{#pragmaompcritical{++i;}}std::cout使用g++-fopenmp-fsanitize=thread编译并运行yieldWARNING:ThreadSanitizer:datarace(pid=9576)Readofsize4at0x7ffdc170f600bythreadT1:#0main._omp_fn.0(a.out+0x000000400d20)#1gomp_thread_start/build/gcc/src/gcc-5.2.0/libgomp/t

c++ - 等价于 C 中的 std::aligned_storage<>?

在C语言中,有没有一种方法可以使堆栈上的存储过度对齐(即比从类型系统推断出的对齐更多)?对于动态分配的内存中的变量,如果所有其他方法都失败了,我们总是可以手动对齐,但是对于自动分配的内存中的变量可以做什么呢?我想可以使用char[size+alignment-1]然后总是使用位操作来访问变量,但这似乎比必要的“有点”暗淡(harharhar;)). 最佳答案 在C2011中,有_Alignas和_Alignof关键字,标题这使得它们的使用稍微不那么难看,类型max_align_t(在中)。例如,你可以写double_Alignas(

c++ - sleep 影响哪个虚拟成员函数被std::thread调用?

我不确定这是否是c++11中的预期行为。这是我发现的一个例子。#include#includeusingnamespacestd;classA{public:virtualvoida()=0;threadt;A():t(&A::a,this){}virtual~A(){t.join();}};classB:publicA{public:virtualvoida(){cout编译运行时$g++-std=c++11-pthreadtest.cpp-otest$./testB::a$但是当sleep被移除时...intmain(){Bb;//this_thread::sleep_for(ch

c++ - 从 std::thread 获取返回码?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:C++:Simplereturnvaluefromstd::thread?有没有办法从std::thread获取返回码?我有一个返回整数的函数,我希望能够在线程完成执行时从该函数获取返回代码。