From a26d1469b6dc69dfe3851b34ce7cd06fb5e28f1e Mon Sep 17 00:00:00 2001 From: Antoine Date: Tue, 6 Jun 2023 15:39:25 +0200 Subject: [PATCH] fix doubloe locking --- src/backend/backend.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/backend.cpp b/src/backend/backend.cpp index f5a260e..afa4fdc 100644 --- a/src/backend/backend.cpp +++ b/src/backend/backend.cpp @@ -86,8 +86,12 @@ int Backend::load(std::string path) { auto model = torch::jit::load(path); model.eval(); model.to(m_device); + + std::unique_lock model_lock(m_model_mutex); m_model = model; m_loaded = 1; + model_lock.unlock(); + m_available_methods = get_available_methods(); m_path = path; return 0; @@ -98,9 +102,7 @@ int Backend::load(std::string path) { } int Backend::reload() { - std::unique_lock model_lock(m_model_mutex); auto return_code = load(m_path); - model_lock.unlock(); return return_code; }