Committed by
GitHub
Lock before push_back the deque for thread safety (#445)
Co-authored-by: hiedean <hiedean@tju.edu.cn>
正在显示
1 个修改的文件
包含
4 行增加
和
1 行删除
| @@ -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; |
-
请 注册 或 登录 后发表评论