Fix race condition on m_tag_to_queue_map

This commit is contained in:
2026-03-02 00:52:27 -05:00
parent 9a0d2c2f99
commit 737cfd2196
3 changed files with 13 additions and 12 deletions

View File

@@ -4,11 +4,11 @@
#ifndef STRING_H #ifndef STRING_H
#define STRING_H #define STRING_H
#include <algorithm>
#include <cctype>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <cctype>
#include <algorithm>
inline std::vector<std::string> split(const std::string &str, const char delimiter) { inline std::vector<std::string> split(const std::string &str, const char delimiter) {
std::vector<std::string> result; std::vector<std::string> result;
@@ -23,14 +23,14 @@ inline std::vector<std::string> split(const std::string &str, const char delimit
} }
inline bool is_integer(const std::string &s) { inline bool is_integer(const std::string &s) {
if (s.empty()) return false; if (s.empty())
return false;
size_t start = 0; size_t start = 0;
if (s[0] == '-' || s[0] == '+') if (s[0] == '-' || s[0] == '+')
start = 1; start = 1;
return start < s.size() && return start < s.size() && std::all_of(s.begin() + start, s.end(), ::isdigit);
std::all_of(s.begin() + start, s.end(), ::isdigit);
} }
#endif // STRING_H #endif // STRING_H

View File

@@ -66,9 +66,10 @@ std::optional<SizeAndSource> MessagingInterface::recv(uint8_t *buffer, const siz
{tag, std::make_unique<BlockingQueue<std::unique_ptr<std::vector<uint8_t>>>>( {tag, std::make_unique<BlockingQueue<std::unique_ptr<std::vector<uint8_t>>>>(
PER_TAG_MAX_QUEUE_SIZE)}); PER_TAG_MAX_QUEUE_SIZE)});
} }
const auto &queue = m_tag_to_queue_map[tag];
lock.unlock(); lock.unlock();
const auto data = m_tag_to_queue_map[tag]->dequeue(MAX_RECV_WAIT_TIME); const auto data = queue->dequeue(MAX_RECV_WAIT_TIME);
if (!data.has_value()) { if (!data.has_value()) {
return std::nullopt; return std::nullopt;
@@ -139,10 +140,10 @@ void MessagingInterface::handle_recv() {
std::make_unique<BlockingQueue<std::unique_ptr<std::vector<uint8_t>>>>( std::make_unique<BlockingQueue<std::unique_ptr<std::vector<uint8_t>>>>(
PER_TAG_MAX_QUEUE_SIZE)}); PER_TAG_MAX_QUEUE_SIZE)});
} }
const auto &queue = m_tag_to_queue_map[mpi_message->tag()];
lock.unlock(); lock.unlock();
m_tag_to_queue_map[mpi_message->tag()]->enqueue(std::move(data.value()), queue->enqueue(std::move(data.value()), MAX_WAIT_TIME_TAG_ENQUEUE);
MAX_WAIT_TIME_TAG_ENQUEUE);
} }
} }
} }