From d0a47783f20f8b177a48418966dae45454193a6a Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Wed, 3 May 2023 11:12:07 +0200 Subject: [PATCH] Use the completion callback to wait The memory allocated is freed after the spawned function is executed. --- test/rt/nanos6/spawn-task-external-bad.c | 18 +++++++++++++++++- test/rt/nanos6/spawn-task-external.c | 17 ++++++++++++++++- test/rt/nanos6/spawn-task.c | 18 +++++++++++++++++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/test/rt/nanos6/spawn-task-external-bad.c b/test/rt/nanos6/spawn-task-external-bad.c index 5e0dbaf..044d340 100644 --- a/test/rt/nanos6/spawn-task-external-bad.c +++ b/test/rt/nanos6/spawn-task-external-bad.c @@ -15,6 +15,9 @@ #include #include "common.h" +#include "compat.h" + +volatile int complete = 0; static double get_time_ms(void) @@ -42,11 +45,19 @@ polling_func(void *arg) } } +static void +complete_func(void *arg) +{ + UNUSED(arg); + complete = 1; +} + /* Call the nanos6_spawn_function from an external thread */ static void * spawn(void *arg) { - nanos6_spawn_function(polling_func, arg, NULL, NULL, "polling_task"); + nanos6_spawn_function(polling_func, arg, + complete_func, NULL, "polling_task"); return NULL; } @@ -71,5 +82,10 @@ main(void) #pragma oss taskwait + while (!complete) + sleep_us(100); + + free(T); + return 0; } diff --git a/test/rt/nanos6/spawn-task-external.c b/test/rt/nanos6/spawn-task-external.c index 470c82c..5710148 100644 --- a/test/rt/nanos6/spawn-task-external.c +++ b/test/rt/nanos6/spawn-task-external.c @@ -18,6 +18,8 @@ #include "compat.h" #include "ovni.h" +volatile int complete = 0; + static double get_time_ms(void) { @@ -44,6 +46,13 @@ polling_func(void *arg) } } +static void +complete_func(void *arg) +{ + UNUSED(arg); + complete = 1; +} + static inline void instr_thread_start(int32_t cpu, int32_t creator_tid, uint64_t tag) { @@ -82,7 +91,8 @@ spawn(void *arg) /* Inform ovni of this external thread */ instr_thread_start(-1, -1, 0); - nanos6_spawn_function(polling_func, arg, NULL, NULL, "polling_task"); + nanos6_spawn_function(polling_func, arg, + complete_func, NULL, "polling_task"); /* Then inform that the thread finishes */ instr_thread_end(); @@ -111,5 +121,10 @@ main(void) #pragma oss taskwait + while (!complete) + sleep_us(100); + + free(T); + return 0; } diff --git a/test/rt/nanos6/spawn-task.c b/test/rt/nanos6/spawn-task.c index 61436bd..8ca2779 100644 --- a/test/rt/nanos6/spawn-task.c +++ b/test/rt/nanos6/spawn-task.c @@ -12,6 +12,9 @@ #include #include "common.h" +#include "compat.h" + +volatile int complete = 0; static double get_time_ms(void) @@ -39,6 +42,13 @@ polling_func(void *arg) } } +static void +complete_func(void *arg) +{ + UNUSED(arg); + complete = 1; +} + int main(void) { @@ -48,12 +58,18 @@ main(void) *T = 100.0; - nanos6_spawn_function(polling_func, T, NULL, NULL, "polling_task"); + nanos6_spawn_function(polling_func, T, + complete_func, NULL, "polling_task"); #pragma oss task label("dummy_task") dummy_work(*T); #pragma oss taskwait + while (!complete) + sleep_us(100); + + free(T); + return 0; }