This fixes the display-server-hangs-forever-when-quitting problem in amdgpu: https://github.com/FreeBSDDesktop/kms-drm/issues/245
Basically this code was waiting for the process to get the exiting flag, but the function would get thread IDs, not proc IDs, so the condition would never arrive.