All Questions
28 questions
1
vote
3
answers
711
views
Passing move-only function arguments to boost::thread constructor
The following works for std::thread. It prints 10 as output, which is what I desire.
void foo(std::unique_ptr<int> && in) {
std::cout << *in;
}
int main(){
auto in = std::...
-1
votes
3
answers
646
views
boost::thread not updating global variable
I am using a wrapper function in an external software to start a new thread, which updates a global variable, but yet this seems invisible to the main thread. I cant call join(), not to block the main ...
10
votes
1
answer
8k
views
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 ...
1
vote
1
answer
420
views
Can I use boost named_semaphore in place of ACE_SEMAPHORE as I am trying to move from ACE to boost libraries?
I am moving my code from ACE library support to boost library support. I need to replace ACE_Semaphore. It seems C++11 doesn't support semaphore methods. I have seen named_semaphore in boost. Another ...
1
vote
0
answers
260
views
boost::thread::interrupt - Can a parent thread interrupt the child thread?
I know that the parent thread can call interrupt() on child thread's object. The child thread on execution of a specified interruption point will raise an exception which will need to be caught by the ...
4
votes
0
answers
96
views
boost::barrier object lifetime — should it be kept alive after all threads reach wait()?
Consider the following:
#include <boost/thread.hpp>
boost::thread spawn() {
boost::barrier barrier{2};
boost::thread ret{[&barrier] {
// some initialization code
...
2
votes
1
answer
244
views
why "boost.thread" call "intrusive_ptr_add_ref" manually?
In boost.thread's start function, the source code is something like that:
bool thread::start_thread_noexcept()
{
uintptr_t const new_thread = _beginthreadex(
0,
0,
...
1
vote
1
answer
54
views
Extracting argument from boost::function
I have a code like this
int foo(int x) {
cout<<"Argument passed x = "<<x;
return x;
}
int main() {
boost::function<void ()> fn = boost::bind(foo, 10);
// can I get ...
0
votes
1
answer
61
views
How can I make this less cpu intensive?
I have a thread which is running in a loop and executing tasks.
outTask::Task* task;
while (!m_out_stop) {
println("abc");
while (m_outQueue.pop(task)) {
println("123");
task-&...
4
votes
1
answer
1k
views
boost::shared_future and when_all with multiple continuations
I've got a DAG of tasks that I'm trying to execute using the boost::shared_future framework.
For example concreteness, consider the data flow graph shown in the figure.
Here's an attempt to code ...
1
vote
1
answer
105
views
Can anybody explain this unexpected result from boost::thread?
Consider the following program built against boost v1.53. I would expect z = 10 as output, but the program prints z = -1294967296. Can anybody explain why?
// g++ -std=c++11 -O2 -Wall -pedantic -...
3
votes
1
answer
545
views
Notify Waiters at Thread Exit
Consider the following example. Suppose you have one producer and N consumers waiting for data. You want to notify the consumers not only whenever the data is ready but also when the producer ...
0
votes
1
answer
388
views
C++ creating thread inside a class gives c2064
Recently i started using boost::thread (also tried with STL - thread) in order to build a chat.
I made at my "server-station" a class that has
void function that get calls from main.cpp which ...
0
votes
1
answer
1k
views
How to use boost::asio::io_service to dispatch jobs between C++11 threads
I need to perform on a multi-core architecture a huge quantity of relatively short tasks.
For this I wanted to use a fixed size thread pool and some reliable implementation of an executor.
I was ...
0
votes
0
answers
89
views
Boost thread v1.53 segmentation fault
The following program produces a segmentation fault, although I don't see any undefined behaviour in the code. It has been compiled with GCC 4.7.3. Do you know the reason of the fault or a possible ...
0
votes
0
answers
981
views
why my compiled boost thread not support boost::thread?
I tried to compile 1.55 boost libraries using Ubuntu 12.04.
The compiled boost libraries does not allow me to use boost::thread or boost::mutex.
When I look inside the boost/thread/mutex.hpp, the ...
3
votes
1
answer
641
views
How do I stop std/boost::thread copying my object rather than passing references?
From the output of this sample project I am seeing three copies of my object created when I'd expect only one. And want only one. How should I fix this?
In my real code ThreadedThing is a ...
0
votes
2
answers
5k
views
"unique_lock has no mutex: Operation not permitted" error when attempting to wait on boost::condition_Variable
I'm trying to use boost::wait_condition to sleep a thread until some new data is available. My function reduces down to this:
bool Node::waitForNewData() const
{
boost::unique_lock<boost::...
2
votes
1
answer
1k
views
Compilation error on using boost::future .then()
I am trying to use boost::future .then() functionality.
The snippet is taken from Boost 1.54.0 thread synchronisation documentation
#include <string>
#include <boost/thread/future.hpp>
...
0
votes
1
answer
866
views
c++ -std=c++11 -stdlib=libc++ with boost.thread gives Segmentation fault: 11 on OSX
Tried to run some sample code.
But something unexpected occured.
I wonder is there any known issus about boost.thread used with libc++ together ?
Program compiled with -std=c++11 or no option runs ...
2
votes
1
answer
2k
views
Error "Error: stray character" when using C++11
I'm running into a strange issue when I try to compile the following simple C++11 code on my machine:
#include <boost/thread/thread.hpp>
It compiles fine with g++ foo.cpp -o foo but chokes on g+...
2
votes
3
answers
776
views
Is possible to get a thread-locking mechanism in C++ with a std::atomic_flag?
Using MS Visual C++2012
A class has a member of type std::atomic_flag
class A {
public:
...
std::atomic_flag lockFlag;
A () { std::atomic_flag_clear (&lockFlag); }
};
There is ...
0
votes
1
answer
1k
views
How to thread a callable function who is method of a class
Using MS VC++ 2012 and Boost library 1.51.0
This is a snapshot of my problem:
struct B {
C* cPtr;
}
struct C {
void callable (int);
}
void function (B* bPtr, int x) {
// error [1] here
...
5
votes
2
answers
3k
views
Creating boost::thread with an std::shared_ptr object instance
I have the following two code segments. The first block compiles and works as expected. However the second block does not compile.
My question is, given the code below what is the correct syntax ...
16
votes
1
answer
2k
views
false sharing in boost::detail::spinlock_pool?
I came across this SO question and reading it over eventually led me to look at boost::detail::spinlock_pool.
The purpose of boost::detail::spinlock_pool is to reduce potential contention for a ...
33
votes
3
answers
13k
views
boost::thread_group in C++11?
Is there anything like boost::thread_group in C++11?
I'm just trying to port my program from using boost:thread to C++11 threads and wasn't able to find anything equivalent.
2
votes
1
answer
827
views
"Flatten" nested futures
I have a helper function which I use to "flatten" nested futures into a single future:
EDIT: Renamed "fold" to "flatten" as suggested.
I'm using the futures from the boost library:
template<...
1
vote
1
answer
1k
views
interruption points and clean exiting
See the following code:
boost::thread_group threads;
boost::barrier barrier(10);
thing pThing;
for( size_t i = 0; i < 10; ++i )
{
threads.create_thread(
[&...