boost-thread

boost thread and process cleanup on windows

佐手、 提交于 2019-12-06 21:44:35
In my program I have a static object that creates a boost::thread. The thread is supposed to run until program termination, but it shouldn't be terminated in random state, so I implemented controled thread termination in this static object's destructor. The problem is that when main() terminates my thread is terminated before the destructor is called. Now the question: is it possible to prevent the thread to be destroyed? Or at least delay it, so that it happens after the destructor is called? Move the termination from the destructor to a function and simply call it before main ends. 来源: https

tr1::hash for boost::thread::id?

北城余情 提交于 2019-12-06 21:15:06
问题 I started to use the unordered_set class from the tr1 namespace to speed-up access against the plain (tree-based) STL map . However, I wanted to store references to threads ID in boost ( boost::thread::id ), and realized that the API of those identifiers is so opaque that you cannot clearly obtain a hash of it. Surprisingly, boost implements parts of the tr1 (including hash and unordered_set ), but it does not define a hash class that is able to hash a thread ID. Looking at the documentation

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

送分小仙女□ 提交于 2019-12-06 14:17:48
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 << ' ' << j << std::endl; std::cin.get(); } The output is: 42 43 43 I thought for a moment and then try this

How to run boost::threads on many processors?

女生的网名这么多〃 提交于 2019-12-06 13:28:42
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 boost::thread(foo)); g.add_thread(new boost::thread(foo)); g.join_all(); } All these threads run on a

Boost threads - passing parameters by reference

拜拜、爱过 提交于 2019-12-06 06:37:02
问题 My application has a section that resembles the following code void SomeClass::OtherMethod(std::vector<std::string>& g) { g.pushback("Something"); } void SomeClass::SomeMethod() { std::vector<std::string> v; boost::thread t(boost::bind(&SomeClass::OtherMethod,this,v) t.join(); std::cout << v[0]; //Why is this empty when the vector created on stack } I wanted to know why the vector v is empty when the vector is created on the stack and it works when it is created on the heap. I was expecting

Visual Studio 2015 c++/CLI boost::thread [duplicate]

人走茶凉 提交于 2019-12-06 06:05:22
This question already has an answer here : How do I create a C++/CLI Winforms app in VS2012? (1 answer) Closed 2 years ago . This issue has been around for all Visual Studio versions, but in VS 2015 the "old tricks" don't seem to work anymore. This is what I have tried: create a Windows Forms application in VS 2013 and 2015 (the macro is missing since VS 2013, so see this post: Can't find Windows Forms Application for C++ ) add boost headers path to Additional Include Directories add #include "boost/thread.hpp" in the cpp add the following preprocessor definitions (BOOST_USE_WINDOWS_H;BOOST

Am I over-engineering per-thread signal blocking?

穿精又带淫゛_ 提交于 2019-12-05 21:49:34
问题 In my applications, I generally want to intercept SIGINT and SIGTERM signals in order to close down gracefully. In order to prevent worker threads from "stealing" signals, I do this in the entrypoint for each: // Block signals in this thread sigset_t signal_set; sigaddset(&signal_set, SIGINT); sigaddset(&signal_set, SIGTERM); sigaddset(&signal_set, SIGHUP); sigaddset(&signal_set, SIGPIPE); pthread_sigmask(SIG_BLOCK, &signal_set, NULL); If I don't, when I perform Ctrl + C , some of the time

C++ Thread question - setting a value to indicate the thread has finished

守給你的承諾、 提交于 2019-12-05 17:10:16
问题 Is the following safe? I am new to threading and I want to delegate a time consuming process to a separate thread in my C++ program. Using the boost libraries I have written code something like this: thrd = new boost::thread(boost::bind(&myclass::mymethod, this, &finished_flag); Where finished_flag is a boolean member of my class. When the thread is finished it sets the value and the main loop of my program checks for a change in that value. I assume that this is okay because I only ever

Boost Thread Access Violation in Boost Log on shutdown

两盒软妹~` 提交于 2019-12-05 15:29:17
I have an application that uses boost logging. During shutdown, it gets an access violation on a null pointer access. When I step through the code to the point of failure, it appears that the boost::log dll is being de-allocated and then boost::thread code tries to access the memory that was once occupied by the log dll. I am not using any boost threads in my own code, and so assume the boost-thread dll is used by boost log. To ensure all sinks are destroyed prior to shutdown, I am calling: core->flush() and core->remove_all_sinks() I am using boost 1.60 and have also tried this with boost 1

Multiprocessor Boost::Thread? All threads running on one processor

社会主义新天地 提交于 2019-12-05 14:16:05
I have a embarrassingly parallel problem that I want to execute on multiple processors. I had supposed that boost::thread would automatically send new threads to new processors, but all of them are executing on the same core as the parent process. Is it possible to get each thread to run on a different processor, or do I need something like MPI? My suspicion is that boost::thread is simply not a multi-processor tool, that I'm asking it to do something it's not designed for. EDIT: my question boils down to this: Why do all the threads execute on one processor? Is there a way to get boost: