HieDean
Committed by GitHub

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

Co-authored-by: hiedean <hiedean@tju.edu.cn>
@@ -304,7 +304,10 @@ void OnlineWebsocketServer::OnMessage(connection_hdl hdl, @@ -304,7 +304,10 @@ void OnlineWebsocketServer::OnMessage(connection_hdl hdl,
304 int32_t num_samples = payload.size() / sizeof(float); 304 int32_t num_samples = payload.size() / sizeof(float);
305 std::vector<float> samples(p, p + num_samples); 305 std::vector<float> samples(p, p + num_samples);
306 306
307 - c->samples.push_back(std::move(samples)); 307 + {
  308 + std::lock_guard<std::mutex> lock(c->mutex);
  309 + c->samples.push_back(std::move(samples));
  310 + }
308 311
309 asio::post(io_work_, [this, c]() { decoder_.AcceptWaveform(c); }); 312 asio::post(io_work_, [this, c]() { decoder_.AcceptWaveform(c); });
310 break; 313 break;