mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-28 09:54:51 +00:00
Improve thread management
This commit is contained in:
parent
677711a238
commit
a64d3c282f
@ -40,7 +40,6 @@
|
|||||||
#include <boost/dynamic_bitset.hpp>
|
#include <boost/dynamic_bitset.hpp>
|
||||||
#include <boost/exception/diagnostic_information.hpp>
|
#include <boost/exception/diagnostic_information.hpp>
|
||||||
#include <algorithm> // for std::reverse
|
#include <algorithm> // for std::reverse
|
||||||
#include <chrono> // std::chrono::seconds
|
|
||||||
#include <cmath> // for std::fmod, std::lround
|
#include <cmath> // for std::fmod, std::lround
|
||||||
#include <cstdlib> // for strtol
|
#include <cstdlib> // for strtol
|
||||||
#include <iostream> // for cout
|
#include <iostream> // for cout
|
||||||
@ -89,12 +88,9 @@ void Rtcm::run_server()
|
|||||||
std::cout << "Starting a TCP/IP server of RTCM messages on port " << RTCM_port << std::endl;
|
std::cout << "Starting a TCP/IP server of RTCM messages on port " << RTCM_port << std::endl;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::thread tq([&] { std::make_shared<Queue_Reader>(io_context, rtcm_message_queue, RTCM_port)->do_read_queue(); });
|
tq = std::thread([&] { std::make_shared<Queue_Reader>(io_context, rtcm_message_queue, RTCM_port)->do_read_queue(); });
|
||||||
tq.detach();
|
t = std::thread([&] { io_context.run(); });
|
||||||
|
|
||||||
std::thread t([&] { io_context.run(); });
|
|
||||||
server_is_running = true;
|
server_is_running = true;
|
||||||
t.detach();
|
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
@ -112,10 +108,11 @@ void Rtcm::stop_service()
|
|||||||
void Rtcm::stop_server()
|
void Rtcm::stop_server()
|
||||||
{
|
{
|
||||||
std::cout << "Stopping TCP/IP server on port " << RTCM_port << std::endl;
|
std::cout << "Stopping TCP/IP server on port " << RTCM_port << std::endl;
|
||||||
rtcm_message_queue->push("Goodbye"); // this terminates tq
|
|
||||||
Rtcm::stop_service();
|
Rtcm::stop_service();
|
||||||
servers.front().close_server();
|
servers.front().close_server();
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
rtcm_message_queue->push("Goodbye"); // this terminates tq
|
||||||
|
tq.join();
|
||||||
|
t.join();
|
||||||
server_is_running = false;
|
server_is_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user