草庐IT

pthread_self

全部标签

c++ - std::priority_queue<> 什么时候进行 self 排序?

我想知道什么时候C++STLpriority_queue自行排序。我的意思是它insert当你push中的项目,或者当你peek时,它会自行排序并给你最高优先级的项目吗?或pop出来?我问这个是因为我的priority_queue将包含一个可能有值更新的数组的索引,我希望它在我执行pq.top();时更新.#include#include#includeusingnamespacestd;intmain(){priority_queuepq;pq.push(2);pq.push(5);//isthefirstelement5now?orwillitupdateagainwhenItop

c++ - 无法在 pthread_create 函数中将 '*void(MyClass::*)(void*) 转换为 void*(*)(void*)

我正在尝试使用“CameraManager”类创建一个新线程,但出现以下错误:cannotconvert'*void(CameraManager::*)(void*)tovoid*(*)(void*)inpthread_createfunction我在cameramanager.h文件中定义:public:void*dequeueLoop(void*ptr);在cameramanager.cpp中voidCameraManager::startDequeuing(){dequeuing=true;dequeueThreadId=pthread_create(&dequeueThread

c++ - pthread_create 段错误

我在我的程序中使用“pthread_create”方法,并在该方法中出现段错误。什么可能导致这个?我正在使用正确的参数类型调用此函数!这是代码:pthread_t*_daemon;void*writer(void*arg){//stuffthatdontinvolve"arg"...}intinitdevice(){if(pthread_create(_daemon,NULL,&writer,NULL)!=0)//seginthisline{cerr注意:在调用pthread_create中的writer之前,我也尝试在没有“&”的情况下运行它,而且-我们尝试向该方法发送一些void*

c++ - 一旦 std :thread makes into C++Ox,pthreads 会过时吗

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭5年前。Improvethisquestion显然我们仍会维护它,但一旦C++标准保证可用,它会有多大用处。随着新标准的出现,同步原语(Mutex、条件变量)会怎样?您是否认为pthread比std::thread更难掌握?

c++ - 如何用 "-pthread"而不是 "-mthread"编译 boost_thread?

我有一个操作系统,编译时没有可用的-mthread。我有-pthread。如何用-pthread而不是-mthread编译boost_thread?我当前的编译器构建日志:./b2-j1--with-threadlink=static--prefix=./install-dirreleasethreading=multi--builddir=./build-dirinstallComponentconfiguration:-chrono:notbuilding-context:notbuilding-date_time:notbuilding-exception:notbuilding

c++ - pthread_key_t 与局部变量

我正在使用Pthread在C++中开发一个多线程程序,我需要在每个线程中分配本地内存。谷歌搜索后,我发现pthread_key_t类型是某种映射,允许您在TLS中分配内存。所以我的问题是线程函数中的局部变量和pthread_key_t有什么区别?你能给出一个pthread_key_t的正确用法示例吗? 最佳答案 线程局部存储和局部变量之间的区别在于线程局部存储不需要是函数的局部变量。一旦声明它们的函数返回,常规局部变量可能不再被访问。使用pthread_getspecific和pthread_setspecific访问的线程特定存储

c++ - 我可以在已经由 main 创建的 pthread 中创建一个 pthread 吗?

如果我在主函数创建的pthread中创建pthread_create会出错吗?如果,我可以,那我该管什么???重要......:我正在做一个套接字编程,我在不同的端口上打开了5个线程,每个线程都在监听端口,每当我收到一条消息时,我想创建一个线程来接收消息和使用pwrite写入文件。那么,我有几个问题,你能帮我吗???如果不是,那么在线程内创建线程的另一种解决方案是什么??或者它会给我一个段错误吗???或者我会遇到一些竞争条件.... 最佳答案 pthread_create创建一个新线程。独立于它在哪里叫。并在监听时为连接创建一个新线

c++ - 是否可以在没有 pthread 的情况下构建 protobuf?

在没有pthread的实时操作系统上需要使用ProtocolBuffers。我可以通过这种方式静态链接protobufg++-g-Wallexample.pb.ccexample.cc-oexample-static-lprotobuf-lpthread但是,如果没有pthread,我会收到链接错误。是否可以将protobuf配置为在没有pthread的情况下工作? 最佳答案 不是真的。参见thisUnresolved问题。有人修补了较旧的protobuf版本以使其不依赖于pthreads,请参阅here-如果你真的需要它,你可能会

C++ pthread阻塞队列死锁(我认为)

我在使用pthreads时遇到问题,我认为我遇到了死锁。我创建了一个我认为有效的阻塞队列,但在进行更多测试后,我发现如果我尝试取消阻塞在blocking_queue上的多个线程,我似乎会遇到死锁。阻塞队列很简单,看起来像这样:templateclassBlocking_Queue{public:Blocking_Queue(){pthread_mutex_init(&_lock,NULL);pthread_cond_init(&_cond,NULL);}~Blocking_Queue(){pthread_mutex_destroy(&_lock);pthread_cond_destro

c++ - 对 self 的 typedef 有什么影响吗?

我遇到过一些具有以下内容的C++代码:typedefRequestRequest;这只是空操作还是这个typedef实际有影响,如果有,它有什么影响? 最佳答案 您可以在第7.1.3节中阅读与C++2003ANSIISOIEC148822003的typedef说明符相关的所有规则。在7.1.3中,2)据说如果名称已经引用某种类型,则允许标识typedef。这是合法的:typedefintRequest;typedefRequestRequest;//Redefines"Request"withnoeffect它不是:typedefR