Fix sched-add race condition
Wait until all tasks have set the handle and then unblock them all.
This commit is contained in:
parent
148598ec8e
commit
fcba4ddc87
@ -13,36 +13,41 @@
|
|||||||
|
|
||||||
static int ncpus = -1;
|
static int ncpus = -1;
|
||||||
static long nruns = 3L;
|
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;
|
static void **handle;
|
||||||
|
|
||||||
#pragma oss task
|
#pragma oss task
|
||||||
static void
|
static void
|
||||||
do_task(int t)
|
do_task(int t)
|
||||||
{
|
{
|
||||||
if(atomic_load(&wait))
|
|
||||||
{
|
|
||||||
handle[t] = nanos6_get_current_blocking_context();
|
handle[t] = nanos6_get_current_blocking_context();
|
||||||
|
if (handle[t] == NULL)
|
||||||
|
abort();
|
||||||
|
|
||||||
|
atomic_fetch_add(&nhandles, 1);
|
||||||
nanos6_block_current_task(handle[t]);
|
nanos6_block_current_task(handle[t]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_run(void)
|
do_run(void)
|
||||||
{
|
{
|
||||||
memset(handle, 0, ntasks * sizeof(void *));
|
memset(handle, 0, ntasks * sizeof(void *));
|
||||||
atomic_fetch_add(&wait, 1);
|
atomic_store(&nhandles, 0);
|
||||||
|
|
||||||
for(int t = 0; t < ntasks; t++)
|
for(int t = 0; t < ntasks; t++)
|
||||||
do_task(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++)
|
for(int t = 0; t < ntasks; t++)
|
||||||
{
|
{
|
||||||
if(handle[t])
|
if (handle[t] == NULL)
|
||||||
|
abort();
|
||||||
|
|
||||||
nanos6_unblock_task(handle[t]);
|
nanos6_unblock_task(handle[t]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user