Dev Guy
2015-12-25 05:22:09 UTC
Hello can some help clear up what I am doing wrong with trying to use
threads with vector? I am coding up a simple async echo, here is a
snippet of the problem area,
for( int i=0; i < threads; ++i )
{
_workers.push_back( std::thread( [this]() {
_sock.get_io_service().run();
} ) );
}
for( auto & t : _workers)
{
t.join();
}
When I run my server and as soon as I connect to it using netcat I get
an exception?
$ ./simple_async_server 5050
terminate called after throwing an instance of 'std::system_error'
what(): Resource deadlock avoided
Aborted (core dumped)
However the following works no matter how many threads.
std::thread t( [this]() { _sock.get_io_service().run(); } );
t.join();
So not clean why it doesn't work when I save the threads in a vector?
threads with vector? I am coding up a simple async echo, here is a
snippet of the problem area,
for( int i=0; i < threads; ++i )
{
_workers.push_back( std::thread( [this]() {
_sock.get_io_service().run();
} ) );
}
for( auto & t : _workers)
{
t.join();
}
When I run my server and as soon as I connect to it using netcat I get
an exception?
$ ./simple_async_server 5050
terminate called after throwing an instance of 'std::system_error'
what(): Resource deadlock avoided
Aborted (core dumped)
However the following works no matter how many threads.
std::thread t( [this]() { _sock.get_io_service().run(); } );
t.join();
So not clean why it doesn't work when I save the threads in a vector?