|Description||A JANA program can hang at the end of processing just after printing a message like: "Merging thread 0".|
The reason for this is because the JEventLoop destructor calls RemoveJEventLoop which adds the thread to the "threads_to_be_joined" vector. If this happens while the main (monitoring) thread is inside of the application mutex lock, it can call pthread_join while the mutex is locked. Meanwhile, the JEventLoop destructor tries calling JApplication::AddFactoriesToDeleteList(). This tries locking the application mutex, but can't since it is already locked by the main thread. Thus, the JEventLoop destructor never exits and consequently, pthread_exit is never called making pthread_join block forever.
One solution for this would be to create a separate mutex for controlling access to the factories_to_delete container.