Hung process in pthread_from_mach_thread_np freezing app

I am investigating an issue where the main thread appears to be hung. It believe I have reproduced it locally a couple times, but it is not very repeatable. Attached are 2 of the backtraces I generated after pausing the application.

I see a dispatch_barrier_sync_f call which “submits a barrier function for execution and waits until that function completes”. This is happening on a number of threads which are all waiting on a ulock_wait.

In both of the deadlocks, there is one thread that has a dispatch_barrier_sync_f which appears to be active. From what we could tell, it is stuck in the function pthread_from_mach_thread_np. I only have assembly code here, but here is some source. It appears to be converting from a mach_thread to a pthread. When I step through the assembly it appears to be stuck in the loop portion of iterating over the pthread list.

It is not clear to me how this fixed loop could hang. Perhaps the memory is corrupted and it is not looping over a valid pthread list?

This may be related to the issue posted here.

Any help would be greatly appreciated, thank you

Have similar issue. My worker thread calls pthread_from_mach_thread_np, while the main thread tries to call pthread_cancel. Both of these functions hold the lock on the list of thread inside pthread lib: https://github.com/apple/darwin-libpthread/blob/2b46cbcc56ba33791296cd9714b2c90dae185ec7/src/pthread.c#L945. So my app gets killed by the watchdog because my main thread deadlocked.

Hung process in pthread_from_mach_thread_np freezing app
 
 
Q