Skip to content

Commit

Permalink
fix-race
Browse files Browse the repository at this point in the history
Signed-off-by: Benoit Jacob <jacob.benoit.1@gmail.com>
  • Loading branch information
bjacob committed Jan 20, 2025
1 parent 1f50538 commit 0675858
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions shortfin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,16 @@ option(SHORTFIN_ENABLE_ASAN "Enable ASAN" OFF)
if(SHORTFIN_ENABLE_ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)

# Enable more ASAN checks.
add_compile_definitions(IREE_SANITIZER_ADDRESS)
endif()

option(SHORTFIN_ENABLE_TSAN "Enable TSAN" OFF)
if(SHORTFIN_ENABLE_TSAN)
add_compile_options(-fsanitize=thread)
add_link_options(-fsanitize=thread)
add_compile_definitions(IREE_SANITIZER_THREAD)
endif()

# Thread safety annotations: Enabled if the compiler supports it.
check_cxx_compiler_flag("-Wthread-safety" SHORTFIN_HAS_THREAD_SAFETY_ANNOTATIONS)
if(SHORTFIN_HAS_THREAD_SAFETY)
Expand Down
6 changes: 5 additions & 1 deletion shortfin/src/shortfin/support/blocking_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ int BlockingExecutor::ThreadInstance::RunOnThread() noexcept {
auto status = iree_wait_source_wait_one(signal_transact.await(),
iree_infinite_timeout());
IREE_CHECK_OK(status);
Task exec_task = std::move(current_task);
Task exec_task;
{
iree::slim_mutex_lock_guard g(executor->control_mu_);
exec_task = std::move(current_task);
}
if (exec_task) {
exec_task();
}
Expand Down

0 comments on commit 0675858

Please sign in to comment.