Questions tagged [boost-thread]

Boost.Thread enables the use of multiple threads of execution with shared data in portable C++ code.

Boost.Thread enables the use of multiple threads of execution with shared data in portable C++ code. It provides classes and functions for managing the threads themselves, along with others for synchronizing data between the threads or providing separate copies of data specific to individual threads.

The Boost.Thread library was originally written and designed by William E. Kempf. For Boost 1.35+, Anthony Williams performed a major rewrite designed to closely follow the proposals presented to the C++ Standards Committee, in particular N2497, N2320, N2184, N2139, and N2094.

As of Boost version 1.50.0 Boost.Thread provides an almost complete implementation of the C++ 2011 Threads library, plus extensions such as shared locks and thread interruption.

885 questions
6
votes
3 answers

how to handle control-c in a boost tcp/udp server

How do I handle the control-C event or stop my boost::asio server. I have a tcp & udp combined server and would like to be able to exit cleanly when I press ctrl-c. I get a first chance exception for unhandled control-C. Here is my code void…
Gentoo
  • 347
  • 2
  • 8
  • 16
6
votes
3 answers

Can mutex implementations be interchanged (independently of the thread implementation)

Do all mutex implementations ultimately call the same basic system/hardware calls - meaning that they can be interchanged? Specifically, if I'm using __gnu_parallel algorithms (that uses openmp) and I want to make the classes they call threadsafe…
Tom
  • 5,219
  • 2
  • 29
  • 45
6
votes
1 answer

Upgrade shared_lock to unique lock usage, timing and design

I am updating a code that previously uses its own read and write lock mechanism (this code was written prior to C++11 and std::shared_mutex does not exist yet) to use the std version of C++. There is two classes named ReadLock and WriteLock, and…
user2300947
  • 450
  • 4
  • 14
6
votes
1 answer

Execute callback function on main thread from std::thread

I have a requirement of executing a callback function on exit of a std::thread and the callback function should be executed on the main thread. On thread creation I need to detach the thread and cannot block the main loop execution for thread…
Tushar
  • 63
  • 1
  • 1
  • 6
6
votes
2 answers

Signals and threads - good or bad design decision?

I have to write a program that performs highly computationally intensive calculations. The program might run for several days. The calculation can be separated easily in different threads without the need of shared data. I want a GUI or a web…
Jens
  • 156
  • 1
  • 5
6
votes
1 answer

Both blocking and non blocking queue

I need to set up a producer-consumer scheme with two threads linked by a queue (the producer pushing tasks into the queue, the consumer executing them as they come). Since the queue will be empty most of the time I must make it so that the consumer…
MadWatch
  • 91
  • 1
  • 3
6
votes
1 answer

How do you lock memory pages to physical RAM in boost (c++)?

I'm messing with shared memory objects in boost, for a real-time C++ application that needs to lock the memory page(s) into physical memory. I'm not seeing a way to do this in boost. I feel like I'm missing something because I know both Windows and…
Chris
  • 613
  • 6
  • 7
6
votes
1 answer

Struggling to get boost shared memory segments to construct

I have some code with which I'm trying to make a shared memory segment. This segment is managed, on this end, from within a class. The shared segment will be used in a "bulletin board" fashion. That is, this one process will write to it, and many…
Andrew Falanga
  • 2,274
  • 4
  • 26
  • 51
6
votes
2 answers

boost::mutex::scoped_lock has been used and It sometimes throws the exception

I am using scoped_lock in my multithread code to exclusively access to some part of code, but sometimes it throws to the exception Access violation writing location .... boost::mutex mMutex; boost::condition mInputQueueNotEmpty; Job*…
6
votes
2 answers

How to compile boost_thread with "-pthread" instead of "-mthread"?

I have an os and compile with no -mthread avaliable. Thow I have -pthread. How to compile boost_thread with -pthread instead of -mthread? My current compiler build log: ./b2 -j1 --with-thread link=static --prefix=./install-dir release…
myWallJSON
  • 9,110
  • 22
  • 78
  • 149
6
votes
1 answer

Got "Bad file descriptor" when use boost::asio and boost::thread

int func(boost::asio::ip::tcp::socket &socket) { boost::system::error_code ec; socket.write_some(boost::asio::buffer("hello world!"), ec); cout << socket.is_open() << endl; if(ec) { cout <<…
leezii
  • 127
  • 1
  • 1
  • 5
6
votes
3 answers

Multi-threaded C++ Message Passing

I am tasked to modify a synchronous C program so that it can run in parallel. The goal is to have it be as portable as possible as it is an open source program that many people use. Because of this, I thought it would be best to wrap the program in…
grouma
  • 626
  • 2
  • 8
  • 18
5
votes
1 answer

Getting the ID of a boost::thread for PostThreadMessage

I have a Visual Studio 2008 C++ project using Boost 1.47.0 where I need to get the native Windows ID of a boost::thread to pass to PostThreadMessage. In Windows Vista and 7, I would just do this: DWORD thread_id = ::GetThreadId(…
PaulH
  • 7,759
  • 8
  • 66
  • 143
5
votes
6 answers

Boost, mutex concept

I am new to multi-threading programming, and confused about how Mutex works. In the Boost::Thread manual, it states: Mutexes guarantee that only one thread can lock a given mutex. If a code section is surrounded by a mutex locking and unlocking,…
2607
  • 4,037
  • 13
  • 49
  • 64
5
votes
2 answers

CMake and Boost

I've searched and found out that a lot of people have the same problem, but no solution exists. I'm using CMake to generate Makefiles for MinGW and when compiling I'm getting an…
Nemanja Miljković
  • 997
  • 1
  • 6
  • 13