Skip to content

Commit 3df32aa

Browse files
authored
Fix returning an empty task_handle from task_group task (#1867)
1 parent 981eb42 commit 3df32aa

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

include/oneapi/tbb/task_group.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ namespace {
137137
task_handle th = std::forward<F>(f)();
138138
task_handle_task* task_ptr = task_handle_accessor::release(th);
139139
// If task has unresolved dependencies, it can't be bypassed
140-
if (task_ptr->has_dependencies() && !task_ptr->release_dependency()) {
140+
if (task_ptr && task_ptr->has_dependencies() && !task_ptr->release_dependency()) {
141141
task_ptr = nullptr;
142142
}
143143

test/tbb/test_task_group.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,16 @@ TEST_CASE("Task handle for scheduler bypass"){
11721172

11731173
tg.wait();
11741174
CHECK_MESSAGE(run == true, "task handle returned by user lambda (bypassed) should be run");
1175+
1176+
// Test returning an empty handle
1177+
run = false;
1178+
tg.run([&] {
1179+
run = true;
1180+
return tbb::task_handle{};
1181+
});
1182+
1183+
tg.wait();
1184+
CHECK(run == true);
11751185
}
11761186

11771187
//! The test for task_handle inside other task waiting with run_and_wait
@@ -1187,6 +1197,13 @@ TEST_CASE("Task handle for scheduler bypass via run_and_wait"){
11871197
});
11881198

11891199
CHECK_MESSAGE(run == true, "task handle returned by user lambda (bypassed) should be run");
1200+
1201+
// Test returning an empty handle
1202+
run = false;
1203+
tg.run_and_wait([&] {
1204+
run = true;
1205+
});
1206+
CHECK(run == true);
11901207
}
11911208
#endif //__TBB_PREVIEW_TASK_GROUP_EXTENSIONS
11921209

0 commit comments

Comments
 (0)