I have an issue with TBB that makes my application crash systematically on exit.
I use automatic task_scheduler_init and sometimes spawn new tasks within tbb threads.
The culprit is when one of these tasks interacts with the Qt library, internally Qt initializes (even if not needed) a thread local object (using pthread), that must live at least as long as the QApplication object (because it uses method on it).
Basically, what happens is that TBB threads only really stop when the whole process is terminating. With their termination, the pthread local storage created by Qt is destroyed, however, the QApplication object of my application is long gone when the process actually exit.
Actually there's no workaround for me, the QApplication object is always destroyed before the actual handlers of the thread local storage are invoked.
This behavior happens only because I'm unable to join the threads spawned by tbb earlier. Is there any way to actually enforce the lifetime of TBB threads ?
I tried to control myself the lifetime of the task_scheduler_init object but it is in some cases unfeasible because of very complex inter-threads communication schemes which would require the thread that actually spawned a task to necessarily wait on it later on (which is a strong requirement!).
I'm aware of the following blog post regarding initialization/termination of the task scheduler https://software.intel.com/en-us/blogs/2011/04/09/tbb-initialization-termination-and-resource-management-details-juicy-and-gory
but it didn't help.
Anybody has a potential workaround or idea on how to fix this ?