Skip to content

Commit

Permalink
[Core] Fix race condition in CSampleSender::Send() #1332 (#1333)
Browse files Browse the repository at this point in the history
This PR protects the m_payload member variable and thus makes the Send() function reentrant, as it may be called simultaneously from different threads.

Co-authored-by: Florian Reimold <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 24, 2024
1 parent 3dd14af commit 16acfd2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions ecal/core/src/io/udp/ecal_udp_sample_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace eCAL
{
if (!m_udp_sender) return(0);

std::lock_guard<std::mutex> const send_lock(m_payload_mutex);
// return value
size_t sent_sum(0);

Expand Down
2 changes: 2 additions & 0 deletions ecal/core/src/io/udp/ecal_udp_sample_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#endif

#include <memory>
#include <mutex>
#include <vector>

namespace eCAL
Expand All @@ -51,6 +52,7 @@ namespace eCAL
IO::UDP::SSenderAttr m_attr;
std::shared_ptr<IO::UDP::CUDPSender> m_udp_sender;

std::mutex m_payload_mutex;
std::vector<char> m_payload;
};
}
Expand Down

0 comments on commit 16acfd2

Please sign in to comment.