Detached tasks behavior changed

Hi everyone,

I've noticed in 9d64275a the behavior of detached tasks has changed. From this commit now the runtime does not taskwait the detached task until completion. If I understand correctly, detached tasks behave like a proxy task, and proxy tasks are taskwaited until completion.

I attach test that creates a detached or proxy task that performs a sleep to check that the master thread stays in the taskwait.

// test.c

#if !defined(DETACH) && !defined(PROXY)
#error Use -DDETACH or -DPROXY to compile the test

#include <stdio.h>
#include <pthread.h>
#include <omp.h>
#include <unistd.h>

// detached
// proxy
#define PTASK_FLAG_PROXY 0x10

// OpenMP RTL interfaces
typedef long long kmp_int64;

typedef struct ID {
int reserved_1;
int flags;
int reserved_2;
int reserved_3;
char *psource;
} id;

// Compiler-generated code (emulation)
typedef struct ident {
void* dummy; // not used in the library
} ident_t;

typedef enum kmp_event_type_t {
} kmp_event_type_t;

typedef struct {
kmp_event_type_t type;
union {
void *task;
} ed;
} kmp_event_t;

typedef struct shar { // shareds used in the task
} *pshareds;

typedef struct task {
pshareds shareds;
int(*routine)(int,struct task*);
int part_id;
// void *destructor_thunk; // optional, needs flag setting if provided
// int priority; // optional, needs flag setting if provided
// ------------------------------
// privates used in the task:
omp_event_handle_t evt;
} *ptask, kmp_task_t;

typedef int(* task_entry_t)( int, ptask );

#ifdef __cplusplus
extern "C" {
extern int __kmpc_global_thread_num(void *id_ref);
extern int** __kmpc_omp_task_alloc(id *loc, int gtid, int flags,
size_t sz, size_t shar, task_entry_t rtn);
extern int __kmpc_omp_task(id *loc, kmp_int64 gtid, kmp_task_t *task);
extern void __kmpc_proxy_task_completed_ooo ( kmp_task_t *ptask );
extern omp_event_handle_t __kmpc_task_allow_completion_event(
ident_t *loc_ref, int gtid, kmp_task_t *task);
#ifdef __cplusplus

int volatile checker;

void *target(void *task)
sleep( 3 );
checker = 1;
#ifdef DETACH
#ifdef PROXY
return NULL;

pthread_t target_thread;

// User's code
int task_entry(int gtid, ptask task)
pthread_create(&target_thread, NULL, &target, task);
return 0;

int main() {
int gtid = __kmpc_global_thread_num(NULL);
ptask task;
checker = 0;
omp_event_handle_t evt;
#pragma omp task detach(evt)
#ifdef DETACH
task = (ptask)__kmpc_omp_task_alloc(NULL,gtid,PTASK_FLAG_DETACHABLE,
sizeof(struct task),sizeof(struct shar),&task_entry);
evt = (omp_event_handle_t)__kmpc_task_allow_completion_event(NULL,gtid,task);
task->evt = evt;
#ifdef PROXY
task = (ptask)__kmpc_omp_task_alloc(NULL,gtid,PTASK_FLAG_PROXY,
sizeof(struct task),sizeof(struct shar),&task_entry);
__kmpc_omp_task(NULL, gtid, task);
#pragma omp taskwait

// check results
if (checker == 1) {
return 0;
} else {
return 1;

// end test.c

To use detached or proxy task use -DDETACH or -DPROXY in the compilation line.

The source line that is performing that behavior is . Previously the code was .



Hi Raúl,

Thanks for your report. I’ll fix it soon.


Hi Raúl,

This patch ( should fix the issue. Can I include your test into the repo?


Sure, thanks also for the quick reply.


WARNING / LEGAL TEXT: This message is intended only for the use of the individual or entity to which it is addressed and may contain information which is privileged, confidential, proprietary, or exempt from disclosure under applicable law. If you are not the intended recipient or the person responsible for delivering the message to the intended recipient, you are strictly prohibited from disclosing, distributing, copying, or in any way using this message. If you have received this communication in error, please notify the sender and destroy and delete any copies you may have received.