Hi! The following patch fixes crashes with posthumous orphan tasks. When a parent task finishes, gomp_clear_parent clears the parent pointers of its children tasks present in the parent->children_queue. But children that are still waiting for dependencies aren't in that queue yet, they will be added there only when the sibling they are waiting for exits. Unfortunately we were adding those tasks into the queues with the original task->parent which then causes crashes because that task is gone and freed. The following patch fixes that by clearing the parent field when we schedule such task for running by adding it into the queues and we know that the sibling task which is about to finish has NULL parent.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk so far, queued for backporting. 2022-02-08 Jakub Jelinek <ja...@redhat.com> PR libgomp/104385 * task.c (gomp_task_run_post_handle_dependers): If parent is NULL, clear task->parent. * testsuite/libgomp.c/pr104385.c: New test. --- libgomp/task.c.jj 2022-01-11 23:11:23.914268738 +0100 +++ libgomp/task.c 2022-02-07 18:33:14.399083055 +0100 @@ -1248,6 +1248,8 @@ gomp_task_run_post_handle_dependers (str } } } + else + task->parent = NULL; if (taskgroup) { priority_queue_insert (PQ_TASKGROUP, &taskgroup->taskgroup_queue, --- libgomp/testsuite/libgomp.c/pr104385.c.jj 2022-02-07 18:45:36.677690756 +0100 +++ libgomp/testsuite/libgomp.c/pr104385.c 2022-02-07 18:45:31.005770166 +0100 @@ -0,0 +1,26 @@ +/* PR libgomp/104385 */ + +#include <unistd.h> + +int +main () +{ + int j = 0; + #pragma omp parallel shared(j) num_threads(2) + { + #pragma omp barrier + #pragma omp master + #pragma omp task shared(j) + { + #pragma omp task depend(out: j) shared(j) + { + usleep (10000); + j = 1; + } + + #pragma omp task depend(inout: j) shared(j) + j += 1; + } + } + return j - 2; +} Jakub