From c0fdc488d21817505553e8aead45263e31b1b119 Mon Sep 17 00:00:00 2001 From: hiedean Date: Fri, 24 Nov 2023 09:56:15 +0800 Subject: [PATCH] Lock before push_back the deque for thread safety --- sherpa-onnx/csrc/online-websocket-server-impl.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sherpa-onnx/csrc/online-websocket-server-impl.cc b/sherpa-onnx/csrc/online-websocket-server-impl.cc index eaf65cfa9..a47e613c8 100644 --- a/sherpa-onnx/csrc/online-websocket-server-impl.cc +++ b/sherpa-onnx/csrc/online-websocket-server-impl.cc @@ -304,7 +304,10 @@ void OnlineWebsocketServer::OnMessage(connection_hdl hdl, int32_t num_samples = payload.size() / sizeof(float); std::vector samples(p, p + num_samples); - c->samples.push_back(std::move(samples)); + { + std::lock_guard lock(c->mutex); + c->samples.push_back(std::move(samples)); + } asio::post(io_work_, [this, c]() { decoder_.AcceptWaveform(c); }); break;