I just found that gcc’s OpenMP implementation (libgomp) doesn’t call pthread_exit().
I need that to use perfsuite (for profiling).
Is there any way to tell GCC to include pthread_exit() at the end of a parallel section of OpenMP while transforming the OpenMP code to pthread codes?
I am using GCC 4.7.0 and Perfsuite 1.1.1 .
libgompimplements thread pools. Once created, a thread in the pool remains idle until it is signalled to become member of a thread team. After the team finishes its work, the thread goes into an idle loop until it is signalled again. The pool grows on demand but never shrinks. Threads are only signalled to exit at program finish.You can read the
libgompcode that implements thread pools and teams in the 4.7.x branch here.Pool threads are terminated like this:
libgompregisters a destructor by the name ofteam_destructor(). It is called whenever themain()function returns,exit(3)gets called or thelibgomplibrary is unloaded by a call todlclose(3)(if previously loaded withdlopen(3)). The destructor deletes onepthreadskey by the name ofgomp_thread_destructor, which has an associated destructor functiongomp_free_thread()triggered by the deletion.gomp_free_thread()makes all threads in the pool executegomp_free_pool_helper()as their next task.gomp_free_pool_helper()callspthread_exit(3)and thus all threads in the pool cease to exist.Here is the same process in a nice ASCII picture:
Note that this only happens once at the end of the program execution and not at the end of each
parallelregion.