Lock before push_back the deque for thread safety (#445)

Co-authored-by: hiedean <hiedean@tju.edu.cn>
This commit is contained in:
HieDean
2023-11-24 10:23:25 +08:00
committed by GitHub
parent 94ef6929bb
commit 2a91524dbf

View File

@@ -304,7 +304,10 @@ void OnlineWebsocketServer::OnMessage(connection_hdl hdl,
int32_t num_samples = payload.size() / sizeof(float);
std::vector<float> samples(p, p + num_samples);
c->samples.push_back(std::move(samples));
{
std::lock_guard<std::mutex> lock(c->mutex);
c->samples.push_back(std::move(samples));
}
asio::post(io_work_, [this, c]() { decoder_.AcceptWaveform(c); });
break;