Fix bug in spawn task tests

The argument passed to nanos6_spawn_function() was being destroyed when
the parent function ends.
This commit is contained in:
Rodrigo Arias 2023-05-02 16:55:47 +02:00
parent 44d120d7a8
commit 7d7c59bbf8
3 changed files with 27 additions and 14 deletions

View File

@ -10,8 +10,9 @@
#include <nanos6.h> #include <nanos6.h>
#include <nanos6/library-mode.h> #include <nanos6/library-mode.h>
#include <time.h>
#include <pthread.h> #include <pthread.h>
#include <stdlib.h>
#include <time.h>
#include "common.h" #include "common.h"
@ -45,8 +46,7 @@ polling_func(void *arg)
static void * static void *
spawn(void *arg) spawn(void *arg)
{ {
double ms = *((double *) arg); nanos6_spawn_function(polling_func, arg, NULL, NULL, "polling_task");
nanos6_spawn_function(polling_func, &ms, NULL, NULL, "polling_task");
return NULL; return NULL;
} }
@ -54,7 +54,11 @@ int
main(void) main(void)
{ {
pthread_t th; pthread_t th;
double T = 100.0; double *T = malloc(sizeof(double));
if (T == NULL)
die("malloc failed:");
*T = 100.0;
if (pthread_create(&th, NULL, spawn, &T) != 0) if (pthread_create(&th, NULL, spawn, &T) != 0)
die("pthread_create failed:"); die("pthread_create failed:");
@ -63,7 +67,7 @@ main(void)
die("pthread_join failed:"); die("pthread_join failed:");
#pragma oss task label("dummy_task") #pragma oss task label("dummy_task")
dummy_work(T); dummy_work(*T);
#pragma oss taskwait #pragma oss taskwait

View File

@ -10,8 +10,9 @@
#include <nanos6.h> #include <nanos6.h>
#include <nanos6/library-mode.h> #include <nanos6/library-mode.h>
#include <time.h>
#include <pthread.h> #include <pthread.h>
#include <stdlib.h>
#include <time.h>
#include "common.h" #include "common.h"
#include "compat.h" #include "compat.h"
@ -81,8 +82,7 @@ spawn(void *arg)
/* Inform ovni of this external thread */ /* Inform ovni of this external thread */
instr_thread_start(-1, -1, 0); instr_thread_start(-1, -1, 0);
double ms = *((double *) arg); nanos6_spawn_function(polling_func, arg, NULL, NULL, "polling_task");
nanos6_spawn_function(polling_func, &ms, NULL, NULL, "polling_task");
/* Then inform that the thread finishes */ /* Then inform that the thread finishes */
instr_thread_end(); instr_thread_end();
@ -94,16 +94,20 @@ int
main(void) main(void)
{ {
pthread_t th; pthread_t th;
double T = 100.0; double *T = malloc(sizeof(double));
if (T == NULL)
die("malloc failed:");
if (pthread_create(&th, NULL, spawn, &T) != 0) *T = 100.0;
if (pthread_create(&th, NULL, spawn, T) != 0)
die("pthread_create failed:"); die("pthread_create failed:");
if (pthread_join(th, NULL) != 0) if (pthread_join(th, NULL) != 0)
die("pthread_join failed:"); die("pthread_join failed:");
#pragma oss task label("dummy_task") #pragma oss task label("dummy_task")
dummy_work(T); dummy_work(*T);
#pragma oss taskwait #pragma oss taskwait

View File

@ -8,6 +8,7 @@
#include <nanos6.h> #include <nanos6.h>
#include <nanos6/library-mode.h> #include <nanos6/library-mode.h>
#include <stdlib.h>
#include <time.h> #include <time.h>
#include "common.h" #include "common.h"
@ -41,12 +42,16 @@ polling_func(void *arg)
int int
main(void) main(void)
{ {
double T = 100.0; double *T = malloc(sizeof(double));
if (T == NULL)
die("malloc failed:");
nanos6_spawn_function(polling_func, &T, NULL, NULL, "polling_task"); *T = 100.0;
nanos6_spawn_function(polling_func, T, NULL, NULL, "polling_task");
#pragma oss task label("dummy_task") #pragma oss task label("dummy_task")
dummy_work(T); dummy_work(*T);
#pragma oss taskwait #pragma oss taskwait