boost-thread

shared_ptr Assertion px != 0 failed

。_饼干妹妹 提交于 2019-12-09 14:02:18
问题 I have a fairly complex multi threaded application (server) that from time to time will crash due to an assert: /usr/include/boost/smart_ptr/shared_ptr.hpp:418: T* boost::shared_ptr< <template-parameter-1-1> >::operator->() const [with T = msg::Player]: Assertion `px != 0' failed. I have been unable to pinpoint the cause and was wondering if this is a problem with boost::shared_ptr or it is me? I tried g++ 4.4.3-4ubuntu5 and llvm-g++ (GCC) 4.2.1 with optimization and without optimization and

Boost Thread Cancelling

一曲冷凌霜 提交于 2019-12-09 12:14:28
问题 Can you cancel a Boost Thread as you would a pthread? I'm writing a simple watchdog to terminate worker threads if they crash and there doesn't seem to be a way to simply cancel a thread in the Boost Thread library. 回答1: They don't support cancel, which is a good thing since it can cause all manner of subtle problems. Take a look at the section of docs that cover thread interruption and the boost::thread_interrupted exception and fashion something that allows you to accomplish what you want

BOOST: recursive shared_mutex?

僤鯓⒐⒋嵵緔 提交于 2019-12-09 08:15:55
问题 Seems that Boost's shared_mutex is non recursive.. Is there anyway around this? (without re implementing the whole stuff) 回答1: have a look at this thread and this excellent explanation why shared_mutex is bad idea in general. so if you don't agree that recursive_mutex is bad idea too, just use it without any shariness because it cannot give you any performance boost. you'll receive even a bit cleaner code w/o any major changes. I tried to use shared_mutex in my project to lock highly

How to kill or Terminate a boost Thread

有些话、适合烂在心里 提交于 2019-12-08 19:39:44
问题 I want to terminate or kill boost thread. code is here: DWORD WINAPI StartFaceDetector(LPVOID temp) { int j=0; char **argv1; QApplication a(j,argv1);//add some thread here gui::VisualControl w; t=&w; boost::thread u(&faceThread); w.show(); a.exec(); // I Want to close u thread here. return 0; } I want to close that boost thread before return of function. Thanks in Advance. 回答1: On Windows: TerminateThread(u.native_handle(), 0); On Linux / QNX / UNIX / any platform with pthread support:

boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error> >

家住魔仙堡 提交于 2019-12-08 19:13:34
问题 I need some help with this exception, I am implementing a NPAPI plugin to be able to use local sockets from browser extensions, to do that I am using Firebreath framework. For socket and connectivity I am using Boost asio with async calls and a thread pool of 5 worker threads. Also I have a deadline per thread to implement a transmission timeout. My extension workflow with the plugin is as this: Open socket 1(this starts a async_receive and the deadline async_wait) Write in the socket 1 Get

Boost threads and non-existant speedups on Linux SMPs

故事扮演 提交于 2019-12-08 03:51:22
问题 I have written a small example C++ program, using boost::thread. Since it's 215 lines, I've posted it on pastebin instead http://pastebin.com/LRZ24W7D The program creates a large number of floats (currently 1gb) and adds them up, first sequentially, and then using a number of threads (hosted inside the device_matrix class). Assuming the machine is a SMP, I'd expect to see a speedup from the code. And on my Windows machine, I see a four-fold speedup, when using 4 device_matrix instances

How to run boost::threads on many processors?

送分小仙女□ 提交于 2019-12-08 02:53:01
问题 I work with a virtual machine computer cluster with many amd64 processors and Debian Squeeze. Previously, I've successfully executed shell scripts in parallel on it (with GNU Parallel). Now, I'd like to use boost::threads. I run this program: #include <boost/thread.hpp> using namespace std; boost::thread_group g; void foo() { for(int i = 0; i < 1000000000; ++i) for(int i = 0; i < 1000000000; ++i); } int main(int argc, char* argv[]) { g.add_thread(new boost::thread(foo)); g.add_thread(new

Why can I call boost::unique_future::get many times, unlike std::future?

谁说我不能喝 提交于 2019-12-07 20:03:58
问题 I know we can't call std::future::get many times, and we should use std::shared_future if we need to call it many times. But we can call boost::unique_future::get many times, although there's boost::shared_future ! void test1() { int i, j; std::future<int> fu1 = std::async([]{ return 42; }); i = fu1.get(); //j = fu1.get(); // error occur std::cout << i << std::endl; boost::unique_future<int> fu2 = boost::async([]{ return 43; }); i = fu2.get(); j = fu2.get(); // sucess...? std::cout << i << '

Is it dangerous to read global variables from separate threads at potentially the same time?

荒凉一梦 提交于 2019-12-07 06:26:04
问题 So I'm writing this neat little program to teach myself threading, I'm using boost::thread and C++ to do so. I need the main thread to communicate with the worker thread, and to do so I have been using global variables. It is working as expected, but I can't help but feel a bit uneasy. What if the the worker thread tries write to a global variable at the same time as the main thread is reading the value. Is this bad, dangerous, or hopefully taken into account behind the scenes?? 回答1: §1.10

How can I immediately cancel a curl operation?

拜拜、爱过 提交于 2019-12-07 02:15:30
问题 I'm using libcurl in C++, and I'm calling curl_easy_perform in a separate thread from my UI using Boost.Thread. The main UI has a cancel button that I'd like to be perfectly responsive (i.e., when a user clicks on it, it should immediately react). I have read, write, and progress callbacks set up to read an atomic should_cancel variable (as in this question), but there are two problems: There's often a very small (but noticeable) delay from when cancel is pressed to when the curl operation