/* * The following code works correctly with Argobots 1.0 and the main branch * without any memory leak. * * 1. The user should not free fifowait_pool. * The primary ES's scheduler and pool may not be freed before ABT_finalize() * since the primary execution stream that is running main() is still using * the scheduler and its pool. Commenting out ABT_pool_free can cause SEGV * or an assertion failure. * * 2. automatic must be ABT_TRUE * The primary ES's scheduler and its pools must be freed regardless of * their "automatic" configuration, but Argobots 1.0 has a bug that */ #include #include #include void thread_f(void *arg) { printf("Hello World!\n"); } int main() { ABT_init(0, 0); ABT_pool fifowait_pool; ABT_bool automatic = ABT_TRUE; /* For Argobots 1.0, it must be ABT_TRUE. */ ABT_pool_create_basic(ABT_POOL_FIFO_WAIT, ABT_POOL_ACCESS_MPMC, automatic, &fifowait_pool); ABT_xstream xstream; ABT_xstream_self(&xstream); ABT_xstream_set_main_sched_basic(xstream, ABT_SCHED_BASIC_WAIT, 1, &fifowait_pool); /* Create a ULT */ ABT_thread thread; ABT_thread_create(fifowait_pool, thread_f, NULL, ABT_THREAD_ATTR_NULL, &thread); ABT_thread_free(&thread); /* Do not free fifowait_pool! */ /* ABT_pool_free(&fifowait_pool); */ /* Finalize Argobots*/ ABT_finalize(); /* No memory leak happens (checked with Valgrind). */ return 0; }