Skip to content

Commit

Permalink
Add guard against invocables returning booleans
Browse files Browse the repository at this point in the history
The guard prevents the use of invocables returning bool in the
bulk_async_execute method of the explicit_scheduler_executor to
avoid data races. Using such invocables can cause issues because
std::vector<return type of the invocable> may be simultaneously
written to by multiple threads, which is problematic
with std::vector<bool> due to its space optimizations.
  • Loading branch information
zhekemist committed Jul 29, 2024
1 parent 41b7edc commit f9da244
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,14 @@ namespace hpx::execution::experimental {
typename hpx::traits::range_traits<S>::value_type;
using result_type = hpx::util::detail::invoke_deferred_result_t<F,
shape_element, Ts...>;


/* A boolean as result_type is disallowed because the elements of a
* vector<bool> cannot be modified concurrently. */
static_assert(!std::is_same_v<result_type, bool>,
"Using an invocable that returns a boolean with "
"explicit_scheduler_executor::bulk_async_execution "
"can result in data races!");

#ifdef HPX_HAVE_STDEXEC
// We are using HPX's bulk implementation for now, so this works for
// other types too.
Expand Down

0 comments on commit f9da244

Please sign in to comment.