草庐IT

thread_posixs

全部标签

c++ - 表达式不是积分常量 clang libc++ threading

我试图在我的linux机器(ubuntu)上编译一个非常简单的线程程序,但即使我指定了libc++,clang似乎仍然向我抛出错误。我的程序是:#include#includevoidcall_from_thread(){std::cout生成文件:CC=clang++CFLAGS=-std=c++11-stdlib=libc++-pthread-c-Wall#properdeclarationoflibc++,butstillanerror...LDFALGS=SOURCES=main.cppOBJECTS=$(SOURCES:.cpp=.o)EXECUTABLE=bimapall:

c++ - boost::thread 变量的前向声明

有人可以告诉我我们可以转发声明一个boost::thread变量吗?boost::线程t(线程);启动一个线程,但我想在某处声明它并在其他地方启动它。提前谢谢。当我使用boost::threadt;t=boost::thread(thread);/usr/include/boost/noncopyable.hpp:Incopyconstructor‘boost::thread::thread(constboost::thread&)’:/usr/include/boost/noncopyable.hpp:27:error:‘boost::noncopyable_::noncopyabl

c++ - posix 管道作为工作队列

我见过的工作队列的正常实现涉及互斥锁和条件变量。消费者:A)AcquiresLockB)WhileQueueemptyWaitonConditionVariable(thussuspendingthreadandreleasinglock)C)WorkobjectretrievedfromqueueD)LockisreleasedE)DoWorkF)GOTOA制作人:A)AcquiresLockB)WorkisaddedtoqueueC)conditionvariableissignaled(potentiallyreleasingworker)D)Lockisreleased我一直在

c++ - 从 64 位整数秒数创建一个 boost::posix_time::ptime 对象

我有一个32位Linux系统,我必须在其中记录时间戳为1901-01-0100:00:00的UINT32秒偏移量的数据。计算时间戳对我来说没问题,因为我可以使用64位ticks()计数器和ticks_per_second()函数生成自纪元以来的秒数如下(我只需要二级分辨率)constptimeptime_origin(time_from_string("1901-01-0100:00:00"));time_durationmy_utc=microsec_clock::universal_time()-ptime_origin;boost::int64_ttick_per_sec=my_

c++ - 究竟什么时候初始化在全局范围内声明的 thread_local 变量?

例如:#includethread_localintn=1;voidf(){++n;//isninitializedhereforeachthreadorpriortoenteringf()?}intmain(){std::threadta(f);std::threadtb(f);ta.join();tb.join();}从here还不完全清楚n什么时候初始化。 最佳答案 足够简单,并且完全符合规范。n将在新线程运行时被初始化-在您输入任何线程特定的函数之前。准确的说是要初始化3次 关于

c++ - 如何终止 std::thread?

我目前正在开发一个程序,需要从socket服务器下载一些图片,下载工作会执行很长时间。因此,我创建了一个新的std::thread来执行此操作。下载完成后,std::thread会调用当前类的一个成员函数,但这个类很可能已经被释放了。所以,我得到了一个异常(exception)。如何解决这个问题?voidxxx::fun1(){...}voidxxx::downloadImg(){...alongtimeif(downloadComplete){this->fun1();}}voidxxx::mainProcees(){std::thread*th=newthread(mem_fn(&

c++ - 为什么 std::atomic_thread_fence 有 "C"链接?

我猜不出为什么这个函数需要“C”而不是“C++”链接。 最佳答案 由LWGissue1479添加这是针对C++11的最后一分钟评论。此更改的基本原理是C语言兼容性(C11线程库在stdatomic.h中具有同名函数atomic_thread_fence)。据我所知,C和C++原子库可以共存一直是一个计划:其他兼容性示例是std::atomic的C兼容类型别名,例如atomic_int和C兼容性宏ATOMIC_VAR_INIT 关于c++-为什么std::atomic_thread_fen

c++ - 并行使用 std::thread?

我是std::thread的新手,我尝试编写一个parallel_for。我编写了以下代码://parallel_for.cpp//compilation:g++-O3-std=c++0xparallel_for.cpp-oparallel_for-lpthread//execution:time./parallel_for10050000000//(100:numberofthreads,50000000:vectorsize)#include#include#include#include#include#include#include#include#include//Paral

c++ - 十进制值:cout << dec << boost::this_thread::get_id()

是否可以用十进制或八进制格式计算thread::id?std::cout我总是得到十六进制,例如0xdf08。 最佳答案 您应该能够使用标准I/O操纵器指定您想要的输出格式:#include//...std::cout但是,请注意thread::id不需要是数字。此外,它可能是一个数字,但可能以不同于将该数字插入std::cout的方式打印到标准输出。.C++11标准规范operator的重载接受std::thread::id(我假设它的行为类似于Boost对boost::thread::it的对应重载),说:[...]Insert

c++ - 是否有 posix_memalign 的 c++ 对应项?

当我调用posix_memalign要在我的C++代码中为Foo类型的对象分配对齐内存,我需要对该指向void**reinterpret_cast/.一般来说,当我遇到这种情况时,这意味着我缺少某些语言功能。也就是说,当我应该调用new时,感觉我在c++中调用了malloc。,在c++中是否有类型感知的new对齐内存分配? 最佳答案 我将从核心建议开始。Foo*aligned_foo(){void*raw=0;if(posix_memalign(&raw,8,sizeof(Foo)))return0;//wecouldthrowor