Never Suspend a Thread in Your Own Process!

2025-04-15
Never Suspend a Thread in Your Own Process!

A customer encountered a long-standing, low-frequency hang: their UI thread called into the kernel and simply hung. The kernel dump couldn't show a user-mode stack trace because the stack had been paged out. Investigation revealed a watchdog thread periodically suspending the UI thread to capture stack traces, but this time it hung for over five hours. The root cause: a deadlock. The watchdog thread, attempting to get a stack trace, needed a function table lock, but the UI thread was suspended, holding the lock. The article emphasizes never suspending a thread within its own process, as it risks deadlocks due to resource contention. To suspend a thread and capture its stack, do so from another process to avoid deadlocks.