Search code examples
linuxmultithreadingshared-librarieslibcuclibc

uClibc shared libs unloading during exit()


I'm using a shared library that creates worker threads during initialization. The app is linked with uClibc. When it returns from main() it crashes in __pthread_cond_wait() or similar from a worker thread that the shared lib doesn't properly stop from its cleanup() code. The main() thread stack when it crashes is:

#0 _dl_munmap from uClibc.so
#1 _dl_fini 
#2 __GI_exit 
#3 __uClibc_main

Since I don't have source for the shared library I can't fix the worker cleanup code, but my question is:

Why are threads still running (crashing) once uClibc starts unloading shared libs ? I assume it's unloading them from the _dl_munmap stack entry above. Is there a way to make sure all threads are paused/stopped when main() exits ?


Solution

  • Why are threads still running

    Because you (or the shared library you link against) left them running.

    Is there a way to make sure all threads are paused/stopped when main() exits

    Yes: you need to arrange for threads to terminate. Without access to the shared library source, you can't really do that; your only other choice is to call _exit (which should not run any cleanup) instead of exit (or instead of returning from main).