Fix sched-add race condition

Wait until all tasks have set the handle and then unblock them all.
This commit is contained in:
Rodrigo Arias 2022-09-29 12:32:56 +02:00
parent 148598ec8e
commit fcba4ddc87

View File

@ -13,36 +13,41 @@
static int ncpus = -1;
static long nruns = 3L;
static long ntasks = 1000L;
static long ntasks = 200L;
static atomic_int wait = 0;
static atomic_int nhandles = 0;
static void **handle;
#pragma oss task
static void
do_task(int t)
{
if(atomic_load(&wait))
{
handle[t] = nanos6_get_current_blocking_context();
if (handle[t] == NULL)
abort();
atomic_fetch_add(&nhandles, 1);
nanos6_block_current_task(handle[t]);
}
}
static void
do_run(void)
{
memset(handle, 0, ntasks * sizeof(void *));
atomic_fetch_add(&wait, 1);
atomic_store(&nhandles, 0);
for(int t = 0; t < ntasks; t++)
do_task(t);
atomic_fetch_sub(&wait, 1);
/* Wait for all tasks to fill the handle */
while (atomic_load(&nhandles) < ntasks);
/* Is ok if we call unblock before the block happens */
for(int t = 0; t < ntasks; t++)
{
if(handle[t])
if (handle[t] == NULL)
abort();
nanos6_unblock_task(handle[t]);
}