wait(2) cannot return detached threads.

Fix by @michi42.