Use the completion callback to wait

The memory allocated is freed after the spawned function is executed.
This commit is contained in:
Rodrigo Arias 2023-05-03 11:12:07 +02:00
parent 7d7c59bbf8
commit d0a47783f2
3 changed files with 50 additions and 3 deletions

View File

@ -15,6 +15,9 @@
#include <time.h>
#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;
}

View File

@ -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;
}

View File

@ -12,6 +12,9 @@
#include <time.h>
#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;
}