boost-thread

Randomly endless thread and various bugs, while parallel line-by-line reading/writing

Hi, I want to implement a parallel reading-processing-writing line by line based on boost::thread, but the current version has indefinite behaviour : the following test reads a CSV file by filling the read (concurrent) queue, which is simply transferred into the writing queue to be written in an output file (no processing for now). Pro...

BOOST: recursive shared_mutex ?

Seems that Boost's shared_mutex is non recursive.. Is there anyway around this? (without re implementing the whole stuff) ...

Give a name to a boost thread?

Is it possible to give a name to a boost::thread so that the debuggers tables and the crash logs can be more readable? How? ...

How to make boost::thread_group execute a fixed number of parallel threads

This is the code to create a thread_group and execute all threads in parallel: boost::thread_group group; for (int i = 0; i < 15; ++i) group.create_thread(aFunctionToExecute); group.join_all(); This code will execute all threads at once. What I want to do is to execute them all but 4 maximum in parallel. When on is terminated, ano...

boost::thread and creating a pool of them!

Hi. boost::thread class has a default constructor which gives a "Not-a-thread", so what is boost::thread t1; good for? Can I give it a function to execute later in the code? and another question: I'm trying to write a little server which has a staged architecture (SEDA), there are a number of worker threads in each stage and the st...

Upgrade of BOOST 1.36 to 1.43 causes linker error

At work we have an MFC Extension DLL that built fine with 1.36 but when built with 1.43 causes the following error: error LNK2005: __pRawDllMain already defined in ApObs.obj If I activate BOOST_LIB_DIAGNOSTIC the old build lists: linking to lib file: libboost_thread-vc71-mt-gd-1_35.lib and linking to lib file: libboost_thread-vc7...

shared_ptr Assertion px != 0 failed.

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

Multiple Boost.Thread Instances OK in a C++ application?

I have an application with a plug-in architecture that is using Boost.Threads as a DLL (specifically, a Mac OS X framework). I am trying to write a plug-in that uses Boost.Threads as well, and would like to link in the library statically. Everything builds fine but the application quickly crashes in my plug-in, deep within the Boost.Thre...

Boost Thread not detaching when it is created as a member function of a class.

The simplified version of my code looks as follows: class threadCreator { void threadFunction(void){ // use some private data members and do something. } void createThread(void){ boost::thread myThread( boost::bind(&threadCreator::threadFunction,this)); myThread.detach(); } } This program wa...

Boost thread error

hello, #include <boost/thread/thread.hpp> #include <iostream> void hello() { std::cout << "Hello world, I'm a thread!" << std::endl; } int main(int argc, char* argv[]) { boost::thread thrd(&hello); thrd.join(); return 0; } i ran this program i am getting an error /usr/include/boost/thread/pthread/mutex.hpp:40: und...

How do I make Boost threads run serially, not in parallel?

I have a piece of code which uses Boost threads to speed up the calculation, but I need to debug it and want to run them in series, not in parallel. How do I do that? ...

Why would a friend function be defined as part of a struct - boost thread_data?

I'm trying to understand some boost code which is causing PC-Lint grief and uses the friend keyword in a way which I didn't think was legal C++ but compiles OK in VS2008. I thought I understood friend as a way to declare classes and functions. I didn't think it was legal to use on a function definition like this. However, the MSDN page ...

boost::threads execution ordering

hello i have a problem with the order of execution of the threads created consecutively. here is the code. #include <iostream> #include <Windows.h> #include <boost/thread.hpp> using namespace std; boost::mutex mutexA; boost::mutex mutexB; boost::mutex mutexC; boost::mutex mutexD; void SomeWork(char letter, int index) { boost:...

What if I don't join thread on "destruction" in release builds?

In many cases I have classes that act like active objects (have a thread). And to avoid access violations I always have to wait for join in the destructor. Which is usually not a problem. However imagine a release build with some bug (deadlock, livelock etc.) that causes join() not to return on time or at all, this would cause the enti...

How to use boost::thread mutex to synchronize write access?

I have a newbie question about Boost::Thread and Mutex. I would like to start many parallel instances of the following Worker, and all of them write to the same std::vector: struct Worker { std::vector<double>* vec; Worker(std::vector<double>* v) : vec(v) {} void operator() { // do some long computation and then add results t...

Boost threads: is it possible to limit the run time of a thread before moving to another thread.

I have a program with a main thread and a diagnostics thread. The main thread is basically a while(1) loop that performs various tasks. One of these tasks is to provide a diagnostics engine with information about the system and then check back later (i.e. in the next loop) to see if there are any problems that should be dealt with. An...

boost condition. What am I doing wrong?

boost::condition_variable cond; boost::mutex mut; void Database::run() { boost::unique_lock<boost::mutex> lock(mut); while(true) { while(queries_queue.empty()) cond.wait(lock); mysqlpp::Query* q = queries_queue.front(); // <<< CRASHES HERE <<< q->execute(); queries_queue.pop_fron...

boost::thread assertion error

I'm trying to create a simple test program using boost::thread, but I get a runtime assertion error. Here is the code: #include <iostream> #include <boost/thread.hpp> void hello (void) { std::cout << "Hello, world!" << std::endl; } int main (void) { boost::thread t(&hello); t.join(); // Fails even without this line } T...

memory fences/barriers in C++: does boost or other libraries have them?

I am reading these days about memory fences and barriers as a way to synchronize multithreaded code and avoid code reordering. I usually develop in C++ under Linux OS and I use boost libs massively but I am not able to find any class related to it. Do you know if memory barrier of fences are present in boost or if there is a way to ach...

How to use lock_guard when returning protected data

I have a question concerning the use of boost::lock_guard (or similar scoped locks) and using variables that should be protected by the lock in a return statement. How is the order of destroying local objects and copying the return value? How does return value optimization affect this? Example: Data Class::GetData() { boost::lock_...