Код: Выделить всё
void listenerTask()
{
while(true) {
uint8_t buffer[1024]= {0};
const auto receivedBytes = receive(buffer, sizeof(buffer));
const auto rxTimeStamp = std::chrono::steady_clock::now();
std::lock_guard lock(m_mutex);
m_queue.emplace(std::vector(buffer, buffer + receivedBytes), rxTimeStamp);
m_notifier.notify_one();
}
}
void processorTask()
{
while(true) {
const auto rxEntry = [&]() {
std::unique_lock lock(m_mutex);
m_notifier.wait(lock, [this] { return !m_queue.empty(); });
return m_queue.front();
}();
{
std::lock_guard lock(m_mutex);
m_queue.pop();
}
// TODO Process the received data
}
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... n-stdqueue