Skip to content

Commit 651de06

Browse files
authored
[xnnpack] Serialize Access to delegate::init
Differential Revision: D68302913 Pull Request resolved: #7719
1 parent 2411c99 commit 651de06

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

backends/xnnpack/runtime/XNNPACKBackend.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ class XnnpackBackend final : public ::executorch::runtime::BackendInterface {
7676
auto executor = ET_ALLOCATE_INSTANCE_OR_RETURN_ERROR(
7777
context.get_runtime_allocator(), xnnpack::delegate::XNNExecutor);
7878

79+
#ifdef ENABLE_XNNPACK_SHARED_WORKSPACE
80+
// This is needed to serialize access to xnn_create_runtime which is not
81+
// thread safe. This can heppen when multiple threads call init() on
82+
// the same backend instance.
83+
const std::lock_guard<std::mutex> lock(workspace_mutex_);
84+
#endif
85+
7986
// Executor has been allocated but not constructed, ensure that runtime_ is
8087
// nullptr by constructing it in place here. NOTE: Since we use placement
8188
// new and since this type is not trivially destructible, we must call the

0 commit comments

Comments
 (0)