void thread_func(void *arg) { int ret; arg_t *my_arg = (arg_t *)arg; ABT_test_printf(3, "[U%d:E%d] %s\n", my_arg->tid, my_arg->eid, my_arg->op_type == OP_WAIT ? "wait" : "set"); if (my_arg->op_type == OP_WAIT) { if (my_arg->nbytes == 0) { ret = ABT_eventual_wait(my_arg->ev, NULL); } else { void *val; ret = ABT_eventual_wait(my_arg->ev, &val); assert(*(int *)val == 1); } ABT_TEST_ERROR(ret, "ABT_eventual_wait"); } else if (my_arg->op_type == OP_SET) { if (my_arg->nbytes == 0) { ret = ABT_eventual_set(my_arg->ev, NULL, 0); } else { int val = 1; ret = ABT_eventual_set(my_arg->ev, &val, sizeof(int)); } ABT_TEST_ERROR(ret, "ABT_eventual_set"); } ABT_test_printf(3, "[U%d:E%d] done\n", my_arg->tid, my_arg->eid); }
void task_func(void *arg) { int ret; arg_t *my_arg = (arg_t *)arg; assert(my_arg->op_type == OP_SET); if (my_arg->nbytes == 0) { ret = ABT_eventual_set(my_arg->ev, NULL, 0); } else { int val = 1; ret = ABT_eventual_set(my_arg->ev, &val, sizeof(int)); } ABT_TEST_ERROR(ret, "ABT_eventual_set"); }
void fn3(void *args) { ABT_TEST_UNUSED(args); int i = 0; ABT_test_printf(1, "Thread 3 iteration %d signal eventual \n", i); char *data = (char *) malloc(EVENTUAL_SIZE); ABT_eventual_set(myeventual, data, EVENTUAL_SIZE); ABT_test_printf(1, "Thread 3 continue iteration %d \n", i); }
/* Function to compute Fibonacci numbers */ void fibonacci_thread(void *arguments) { int n, *n1, *n2; thread_args a1, a2; ABT_eventual eventual, f1, f2; thread_args *args = (thread_args *)arguments; n = args->n; eventual = args->eventual; /* checking for base cases */ if (n <= 2) args->result = 1; else { ABT_eventual_create(sizeof(int), &f1); a1.n = n - 1; a1.eventual = f1; ABT_thread_create(g_pool, fibonacci_thread, &a1, ABT_THREAD_ATTR_NULL, NULL); ABT_eventual_create(sizeof(int), &f2); a2.n = n - 2; a2.eventual = f2; ABT_thread_create(g_pool, fibonacci_thread, &a2, ABT_THREAD_ATTR_NULL, NULL); ABT_eventual_wait(f1, (void **)&n1); ABT_eventual_wait(f2, (void **)&n2); args->result = *n1 + *n2; ABT_eventual_free(&f1); ABT_eventual_free(&f2); } /* checking whether to signal the eventual */ if (eventual != ABT_EVENTUAL_NULL) { ABT_eventual_set(eventual, &args->result, sizeof(int)); } }