Skip to content

Commit

Permalink
fixed deadlock error in test
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan511 committed Feb 8, 2024
1 parent 3b62fca commit 600b4a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace hpx::synchronization {
std::error_code ec = std::make_error_code(
std::errc::resource_deadlock_would_occur);
throw std::system_error(
ec, "unique_lock::lock: already locked");
ec, "range_unique_lock::lock: already locked");
}
lock_id = mutex_ref.get().lock(begin, end);
}
Expand All @@ -115,7 +115,7 @@ namespace hpx::synchronization {
std::error_code ec = std::make_error_code(
std::errc::resource_deadlock_would_occur);
throw std::system_error(
ec, "unique_lock::lock: already locked");
ec, "range_unique_lock::lock: already locked");
}
lock_id = mutex_ref.get().try_lock(begin, end);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
int main()
{
hpx::synchronization::range_mutex rm;
hpx::synchronization::range_unique_lock<hpx::synchronization::range_mutex>
lg(rm, 1, 2);
{
hpx::synchronization::range_unique_lock<
hpx::synchronization::range_mutex>
lg(rm, 1, 2);
}
hpx::ranged_lock::test::util::test_lock_n_times<
hpx::synchronization::range_mutex>(
10, 1'00'000, 4, 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ namespace hpx::ranged_lock::test::util {
1) Generates increment num_threads * num_incr_per_thread valid ranges
2) Spawns num_threads threads and assigns all equal amount of work
3) Checks if result is valid

NOTE : Critical Section should take care of obtaining the lock
passed as first parameter
*/
template <typename Lock, typename RangeEndGen, typename CriticalSection>
template <typename RangeMutex, typename RangeEndGen,
typename CriticalSection>
void test_lock_once(std::size_t const len, std::size_t const num_threads,
std::size_t const num_incr_per_thread, RangeEndGen&& range_end_gen,
CriticalSection&& critical_section)
Expand All @@ -88,7 +89,7 @@ namespace hpx::ranged_lock::test::util {
get_increment_ranges(num_incr_per_thread * num_threads, len,
std::forward<RangeEndGen>(range_end_gen));

Lock bl;
RangeMutex rmtx;

for (std::size_t i = 0; i != num_threads; i++)
{
Expand All @@ -99,18 +100,18 @@ namespace hpx::ranged_lock::test::util {
increments.begin() + ((i + 1) * num_incr_per_thread);

threads.emplace_back(
[&bl, &v, &critical_section, start_iter, end_iter]() {
[&rmtx, &v, &critical_section, start_iter, end_iter]() {
increments_ty::iterator it = start_iter;
for (; it != end_iter; ++it)
{
std::size_t begin = it->first;
std::size_t end = it->second;

std::size_t lockId = bl.lock(begin, end);
std::size_t lockId = rmtx.lock(begin, end);

critical_section(v, begin, end);

bl.unlock(lockId);
rmtx.unlock(lockId);
}
});
}
Expand Down

0 comments on commit 600b4a2

Please sign in to comment.