Verwenden Sie Stränge anstelle von Mutexes in einem Multi-Thread-Programm

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Verwenden Sie Stränge anstelle von Mutexes in einem Multi-Thread-Programm

by Guest » 08 Feb 2025, 17:46

Ich möchte ASIO verwenden, um über TCP mit einem Gerät zu kommunizieren. Genauer gesagt gibt es mehrere Ports auf dem Gerät, die für die Kommunikation verwendet werden. Die Kommunikation erfolgt in einem Anfrage-Response-Materie. Diese Anfragen können jederzeit erfolgen. > < /p>

Code: Select all

#include 
#include 
#include 
namespace asio = boost::asio;
using namespace asio::experimental::awaitable_operators;
using namespace std::chrono_literals;

using std::this_thread::sleep_for;
static thread_local int const t_id = [] {
static std::atomic_int gen = 0;
return ++gen;
}();

#include 
static auto stamp()  {
static const auto start = std::chrono::steady_clock::now();
return (std::chrono::steady_clock::now() - start)/1ms;
}
#define TRACE()                                                                                              \
std::osyncstream(std::cout)

Top