1 // RUN: %libomp-cxx-compile-and-run
11 #define PTASK_FLAG_DETACHABLE 0x40
13 // OpenMP RTL interfaces
14 using kmp_int32
= int32_t;
24 // Compiler-generated code (emulation)
25 typedef struct ident
{
26 void *dummy
; // not used in the library
29 typedef enum kmp_event_type_t
{
30 KMP_EVENT_UNINITIALIZED
= 0,
31 KMP_EVENT_ALLOW_COMPLETION
= 1
35 kmp_event_type_t type
;
41 typedef struct shar
{ // shareds used in the task
46 int (*routine
)(int, struct task
*);
48 // void *destructor_thunk; // optional, needs flag setting if provided
49 // int priority; // optional, needs flag setting if provided
50 // ------------------------------
51 // privates used in the task:
52 omp_event_handle_t evt
;
53 } * ptask
, kmp_task_t
;
55 typedef int (*task_entry_t
)(int, ptask
);
60 extern int __kmpc_global_thread_num(void *id_ref
);
61 extern int **__kmpc_omp_task_alloc(id
*loc
, int gtid
, int flags
, size_t sz
,
62 size_t shar
, task_entry_t rtn
);
63 extern kmp_int32
__kmpc_omp_task(ident_t
*loc_ref
, kmp_int32 gtid
,
64 kmp_task_t
*new_task
);
65 extern omp_event_handle_t
__kmpc_task_allow_completion_event(ident_t
*loc_ref
,
74 void target(ptask task
) {
75 std::this_thread::sleep_for(std::chrono::seconds(3));
77 omp_fulfill_event(task
->evt
);
81 int task_entry(int gtid
, ptask task
) {
82 std::thread
t(target
, task
);
87 int main(int argc
, char *argv
[]) {
88 int gtid
= __kmpc_global_thread_num(nullptr);
92 #pragma omp task detach(evt)
95 std::cout
<< "detaching...\n";
96 ptask task
= (ptask
)__kmpc_omp_task_alloc(
97 nullptr, gtid
, PTASK_FLAG_DETACHABLE
, sizeof(struct task
),
98 sizeof(struct shar
), &task_entry
);
99 omp_event_handle_t evt
=
100 (omp_event_handle_t
)__kmpc_task_allow_completion_event(nullptr, gtid
,
104 __kmpc_omp_task(nullptr, gtid
, task
);
110 std::cout
<< "PASS\n";