Skip to content

Commit

Permalink
Ignoring locks to avoid exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Mar 25, 2024
1 parent 92e9a76 commit 66f8e11
Show file tree
Hide file tree
Showing 43 changed files with 203 additions and 107 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2017-2018 Thomas Heller
# Copyright (c) 2015 Martin Stumpf
# Copyright (c) 2022-2024 Hartmut Kaiser
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -806,7 +807,7 @@ jobs:
# is enabled, and other machines may fail similarly.
#
# Having to reconfigure here forces everything to be rebuilt, thus
# we disable it all together.
# we disable it altogether.
#
# cmake \
# -DHPX_WITH_DATAPAR_VC=Off .
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/linux_debug.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2020 ETH Zurich
# Copyright (c) 2024 The STE||AR Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -28,6 +29,8 @@ jobs:
-DHPX_WITH_EXAMPLES=ON \
-DHPX_WITH_TESTS=ON \
-DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \
-DHPX_WITH_VERIFY_LOCKS=ON \
-DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \
-DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On
- name: Build
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/linux_debug_fetch_hwloc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2024 Vedant Nimje
# Copyright (c) 2024 The STE||AR Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -32,6 +33,8 @@ jobs:
-DHPX_WITH_EXAMPLES=ON \
-DHPX_WITH_TESTS=ON \
-DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \
-DHPX_WITH_VERIFY_LOCKS=ON \
-DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \
-DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On
- name: Build
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/macos_debug.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2020 Mikael Simberg
# Copyright (c) 2024 The STE||AR Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -38,6 +39,8 @@ jobs:
-DHPX_WITH_EXAMPLES=ON \
-DHPX_WITH_TESTS=ON \
-DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=3 \
-DHPX_WITH_VERIFY_LOCKS=ON \
-DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \
-DHPX_WITH_CHECK_MODULE_DEPENDENCIES=ON
- name: Build
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/macos_debug_fetch_hwloc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2024 Vedant Nimje
# Copyright (c) 2024 The STE||AR Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -39,6 +40,8 @@ jobs:
-DHPX_WITH_EXAMPLES=ON \
-DHPX_WITH_TESTS=ON \
-DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=3 \
-DHPX_WITH_VERIFY_LOCKS=ON \
-DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \
-DHPX_WITH_CHECK_MODULE_DEPENDENCIES=ON
- name: Build
shell: bash
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/windows_clang_debug.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2020 Mikael Simberg
# Copyright (c) 2022 Hartmut Kaiser
# Copyright (c) 2022-2024 Hartmut Kaiser
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -37,6 +37,8 @@ jobs:
-DHPX_WITH_DEPRECATION_WARNINGS=OFF \
-DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \
-DHPX_COROUTINES_WITH_SWAP_CONTEXT_EMULATION=ON \
-DHPX_WITH_VERIFY_LOCKS=ON \
-DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \
-DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On \
- name: Build
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/windows_debug_vs2019.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2020 Mikael Simberg
# Copyright (c) 2024 The STE||AR Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -36,6 +37,8 @@ jobs:
-DHPX_WITH_DEPRECATION_WARNINGS=OFF \
-DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \
-DHPX_COROUTINES_WITH_SWAP_CONTEXT_EMULATION=ON \
-DHPX_WITH_VERIFY_LOCKS=ON \
-DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \
-DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On
- name: Build
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/windows_debug_vs2022.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2020 Mikael Simberg
# Copyright (c) 2024 The STE||AR Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -36,6 +37,8 @@ jobs:
-DHPX_WITH_DEPRECATION_WARNINGS=OFF \
-DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \
-DHPX_COROUTINES_WITH_SWAP_CONTEXT_EMULATION=ON \
-DHPX_WITH_VERIFY_LOCKS=ON \
-DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \
-DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On
- name: Build
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/windows_debug_vs2022_fetch_hwloc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2024 Vedant Nimje
# Copyright (c) 2024 The STE||AR Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -37,6 +38,9 @@ jobs:
-DHPX_WITH_DEPRECATION_WARNINGS=OFF \
-DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \
-DHPX_COROUTINES_WITH_SWAP_CONTEXT_EMULATION=ON \
-DHPX_COROUTINES_WITH_SWAP_CONTEXT_EMULATION=ON \
-DHPX_WITH_VERIFY_LOCKS=ON \
-DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON \
-DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On
- name: Build
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .jenkins/lsu/env-common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2021 ETH Zurich
# Copyright (c) 2024 The STE||AR Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -9,6 +10,8 @@ configure_extra_options+=" -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=ON"
if [ "${build_type}" = "Debug" ]; then
configure_extra_options+=" -DHPX_WITH_PARCELPORT_COUNTERS=ON"
configure_extra_options+=" -DLCI_DEBUG=ON"
configure_extra_options+=" -DHPX_WITH_VERIFY_LOCKS=ON"
configure_extra_options+=" -DHPX_WITH_VERIFY_LOCKS_BACKTRACE=ON"
fi

ctest_extra_args+=" --verbose "
Expand Down
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1383,15 +1383,9 @@ hpx_option(
OFF CATEGORY "Debugging"
)

set(HPX_WITH_VERIFY_LOCKS_DEFAULT OFF)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(HPX_WITH_VERIFY_LOCKS_DEFAULT ON)
endif()

hpx_option(
HPX_WITH_VERIFY_LOCKS BOOL
"Enable lock verification code (default: OFF, enabled in debug builds)"
${HPX_WITH_VERIFY_LOCKS_DEFAULT}
"Enable lock verification code (default: OFF, enabled in debug builds)" OFF
CATEGORY "Debugging"
ADVANCED
)
Expand Down
2 changes: 1 addition & 1 deletion libs/core/assertion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019 The STE||AR-Group
# Copyright (c) 2019-2024 The STE||AR-Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down
1 change: 1 addition & 0 deletions libs/core/futures/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ add_hpx_module(
hpx_errors
hpx_functional
hpx_logging
hpx_lock_registration
hpx_memory
hpx_serialization
hpx_synchronization
Expand Down
7 changes: 5 additions & 2 deletions libs/core/futures/include/hpx/futures/detail/future_data.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -17,12 +17,13 @@
#include <hpx/futures/traits/future_access.hpp>
#include <hpx/futures/traits/get_remote_result.hpp>
#include <hpx/modules/errors.hpp>
#include <hpx/modules/lock_registration.hpp>
#include <hpx/modules/memory.hpp>
#include <hpx/synchronization/condition_variable.hpp>
#include <hpx/synchronization/spinlock.hpp>
#include <hpx/thread_support/assert_owns_lock.hpp>
#include <hpx/thread_support/atomic_count.hpp>
#include <hpx/threading_base/thread_helpers.hpp>
#include <hpx/type_support/assert_owns_lock.hpp>
#include <hpx/type_support/construct_at.hpp>
#include <hpx/type_support/unused.hpp>

Expand Down Expand Up @@ -467,6 +468,7 @@ namespace hpx::lcos::detail {
// At this point the lock needs to be acquired to safely access the
// registered continuations
std::unique_lock<mutex_type> l(mtx_);
[[maybe_unused]] util::ignore_while_checking il(&l);

// handle all threads waiting for the future to become ready
auto on_completed = HPX_MOVE(on_completed_);
Expand Down Expand Up @@ -544,6 +546,7 @@ namespace hpx::lcos::detail {
// At this point the lock needs to be acquired to safely access the
// registered continuations
std::unique_lock<mutex_type> l(mtx_);
[[maybe_unused]] util::ignore_while_checking il(&l);

// handle all threads waiting for the future to become ready
auto on_completed = HPX_MOVE(on_completed_);
Expand Down
4 changes: 2 additions & 2 deletions libs/core/io_service/src/io_service_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ namespace hpx::threads::detail {

///////////////////////////////////////////////////////////////////////////
bool io_service_thread_pool::run(
std::unique_lock<std::mutex>& l, std::size_t num_threads)
[[maybe_unused]] std::unique_lock<std::mutex>& l,
std::size_t num_threads)
{
HPX_ASSERT(l.owns_lock());
HPX_UNUSED(l);
util::barrier startup(1);
return threads_->run(num_threads, false, &startup);
}
Expand Down
1 change: 1 addition & 0 deletions libs/core/lcos_local/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ add_hpx_module(
hpx_pack_traversal
hpx_errors
hpx_memory
hpx_type_support
CMAKE_SUBDIRS examples tests
)
2 changes: 1 addition & 1 deletion libs/core/lcos_local/include/hpx/lcos_local/and_gate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <hpx/modules/errors.hpp>
#include <hpx/synchronization/no_mutex.hpp>
#include <hpx/synchronization/spinlock.hpp>
#include <hpx/thread_support/assert_owns_lock.hpp>
#include <hpx/type_support/assert_owns_lock.hpp>

#include <cstddef>
#include <mutex>
Expand Down
4 changes: 2 additions & 2 deletions libs/core/lcos_local/include/hpx/lcos_local/channel.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2022 Hartmut Kaiser
// Copyright (c) 2016-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -18,9 +18,9 @@
#include <hpx/modules/memory.hpp>
#include <hpx/synchronization/no_mutex.hpp>
#include <hpx/synchronization/spinlock.hpp>
#include <hpx/thread_support/assert_owns_lock.hpp>
#include <hpx/thread_support/atomic_count.hpp>
#include <hpx/thread_support/unlock_guard.hpp>
#include <hpx/type_support/assert_owns_lock.hpp>
#include <hpx/type_support/unused.hpp>

#include <cstddef>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ namespace hpx::serialization::detail {

void trigger()
{
// hpx::lcos::local::promise<>::set_value() might need to acquire
// a lock, as such, we check the our triggering condition inside a
// hpx::lcos::local::promise<>::set_value() might need to acquire a
// lock, as such, we check our triggering condition inside a
// critical section and trigger the promise outside of it.
bool set_value = false;

Expand Down Expand Up @@ -195,17 +195,15 @@ namespace hpx::serialization::detail {
};
} // namespace hpx::serialization::detail

namespace hpx::util {

// This is explicitly instantiated to ensure that the id is stable across
// shared libraries.
template <>
struct extra_data_helper<serialization::detail::preprocess_futures>
// This is explicitly instantiated to ensure that the id is stable across
// shared libraries.
template <>
struct hpx::util::extra_data_helper<
hpx::serialization::detail::preprocess_futures>
{
HPX_CORE_EXPORT static hpx::util::extra_data_id_type id() noexcept;
static constexpr void reset(
hpx::serialization::detail::preprocess_futures*) noexcept
{
HPX_CORE_EXPORT static extra_data_id_type id() noexcept;
static constexpr void reset(
serialization::detail::preprocess_futures*) noexcept
{
}
};
} // namespace hpx::util
}
};
4 changes: 2 additions & 2 deletions libs/core/lcos_local/include/hpx/lcos_local/trigger.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2022 Hartmut Kaiser
// Copyright (c) 2007-2024 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -15,8 +15,8 @@
#include <hpx/modules/futures.hpp>
#include <hpx/synchronization/no_mutex.hpp>
#include <hpx/synchronization/spinlock.hpp>
#include <hpx/thread_support/assert_owns_lock.hpp>
#include <hpx/thread_support/unlock_guard.hpp>
#include <hpx/type_support/assert_owns_lock.hpp>

#include <cstddef>
#include <mutex>
Expand Down
17 changes: 14 additions & 3 deletions libs/core/lock_registration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2021 The STE||AR-Group
# Copyright (c) 2019-2024 The STE||AR-Group
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -9,13 +9,24 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(lock_registration_headers hpx/lock_registration/detail/register_locks.hpp)
set(lock_registration_sources register_locks.cpp)

if(HPX_WITH_VERIFY_LOCKS_BACKTRACE)
set(additional_dependencies hpx_debugging)
endif()

include(HPX_AddModule)
add_hpx_module(
core lock_registration
GLOBAL_HEADER_GEN ON
ADD_TO_GLOBAL_HEADER "hpx/lock_registration/detail/register_locks.hpp"
SOURCES ${lock_registration_sources}
HEADERS ${lock_registration_headers}
DEPENDENCIES hpx_assertion hpx_concepts hpx_config hpx_errors hpx_functional
hpx_type_support
DEPENDENCIES
hpx_assertion
hpx_concepts
hpx_config
hpx_errors
hpx_functional
hpx_type_support
${additional_dependencies}
CMAKE_SUBDIRS examples tests
)
Loading

0 comments on commit 66f8e11

Please sign in to comment.