Skip to content

Commit

Permalink
Lock before push_back the deque for thread safety (#445)
Browse files Browse the repository at this point in the history
Co-authored-by: hiedean <[email protected]>
  • Loading branch information
HieDean and hiedean authored Nov 24, 2023
1 parent 94ef692 commit 2a91524
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sherpa-onnx/csrc/online-websocket-server-impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2a91524

Please sign in to comment.