boost-thread

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

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. Whe...

Kill a blocked Boost::Thread

I am writing an application which blocks on input from two istreams. Reading from either istream is a synchronous (blocking) call, so, I decided to create two Boost::threads to do the reading. Either one of these threads can get to the "end" (based on some input received), and once the "end" is reached, both input streams stop receivin...

is it possible to create multitreading application in vc6 with boost library?

is it possible to create multitreading application in vc6 with boost library? If possible point to any relevant tutorials. ...

Book for c++ threading?

Is there any good book for c++ threading which uses boost threads. Please post one book per answer ...

Boost Spirit crash when used in DLLs

I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my application. This only happens if I have used the Spirit parser during the lifetime of the process from the main thread. The crash happens at exit and appears to be related to the clean-up of thread specific storage allocated by the Spirit parser....

Multithreading using the boost library

Wish to simultaneously call a function multiple times. I wish to use threads to call a function which will utilize the machines capability to the fullest. This is a 8 core machine, and my requirement is to use the machine cpu from 10% to 100% or more. My requirement is to use the boost class. Is there any way I can accomplish this usi...

boost::thread: Segfault when running optimized version

I have trouble getting boost:thread to work. It runs fine when compiling without optimization: g++ -o test-thread test-thread.cpp -lboost_thread-gcc-mt-s -lpthread ./test-thread But a version that's compiled with optimizations crashes g++ -O2 -o test-thread test-thread.cpp -lboost_thread-gcc-mt-s -lpthread ./test-thread Segmentation ...

How to synchronize threads when polling for state changes with boost

In my application I want to be informed by events, that another application has been started or stopped. I have an existing API to the running application which cannot be changed to accomodate notification which would be the obvious solution. What I have is a function call in the API (isRunning), so I decided to make a polling thread wh...

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

Dear all: 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, boo...

Calling a function with different number of threads passed to the application

I have a function which needs to be invoked with a different number of threads each time (am doing some performance calculation, so need to know when the performance starts deteriorating). Example is given below: getTime() { return 0; } int main() { boost::threadpool::thread_pool<> threads(nThreads); for(int j = 0; j <= nL...

Can I create a software watchdog timer thread in C++ using Boost Signals2 and Threads?

I am running function Foo from somebody else's library in a single-threaded application currently. Most of the time, I make a call to Foo and it's really quick, some times, I make a call to Foo and it takes forever. I am not a patient man, if Foo is going to take forever, I want to stop execution of Foo and not call it with those argum...

Boost Thread Cancelling

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. ...

Crash with boost::thread

Hello, I am using wxwidgets together with boost::thread. The Thread is a worker thread which sends some Events to the GUI: Thread creation: thrd = boost::thread(boost::bind(workerFunction,this)); Send Message to the GUI: wxPostEvent(loWindow, event); wxSafeYield(); Under Windows I don't see any problems, but when starting the app...

Solve boost.thread compilation error with Metrowerks compiler

Hi, I'm trying to use boost.thread with metrowerks codewarrior 5.5.3; in the header thread.hpp, I get the error that he's redefining thread::thread_data: class BOOST_THREAD_DECL thread { private: ... template<typename F> struct thread_data: detail::thread_data_base { F f; thread_data(F f...

Using Boost.Thread headers with MSVC Language Extensions disabled

I just discovered that when Language Extensions are disabled in MSVC, you get this error if you try to include boost/thread/thread.hpp: fatal error C1189: #error : "Threading support unavaliable: it has been explicitly disabled with BOOST_DISABLE_THREADS" It seems that when Boost detects that language extensions are disabled (_MSC...

(simple) boost thread_group question

I'm trying to write a fairly simple threaded application, but am new to boost's thread library. A simple test program I'm working on is: #include <iostream> #include <boost/thread.hpp> int result = 0; boost::mutex result_mutex; boost::thread_group g; void threaded_function(int i) { for(; i < 100000; ++i) {} { boost::mut...

boost.thread dead-lock and self-deletion

I am using boost::thread_group to create(using thread_group::create_thread()) and dispatch threads. In order to limit the max thread numbers, at the end of each thread, I remove the thread from the thread_group and delete the thread itself(so that I could decide whether new threads need to be created). However it hangs somewhere be...

Threads in C, C++, C++0x, pthread and boost

A question about threads in C/C++... C++0x syntax #include <thread> void dummy() {} int main(int, char*[]) { std::thread x(dummy); std::thread y(dummy); ... return 0; } How many threads are there? Two (x and y) or three (x, y and main)? Can I call this_thread::yield() in main? And what do I get from calling this_thread:...

boost microsec_time_clock.hpp warning C4244

Hi. I'm new in using boost and have a problem. I need shared_mutex function in my project. So I've done #include "boost/thread/shared_mutex.hpp" And compiled my project. My MSVC 2005 with "treat warnings as errors" stops compilation because of a warning: c:\\...\microsec_time_clock.hpp(103) : warning C4244: 'argument' : conversion f...

On which platforms is thread local storage limited and how much is available?

I was recently made aware that thread local storage is limited on some platforms. For example, the docs for the C++ library boost::thread read: "Note: There is an implementation specific limit to the number of thread specific storage objects that can be created, and this limit may be small." I've been searching to try and find out the ...