kernel: Have wait_for_thread fail with EDEADLK when the current thread is specified.

This behavior is not required by POSIX (for pthread_join), but it
is recommended and other OSes seem to implement it.

This constitutes a behavioral change from BeOS, which just deadlocked
as we do before this commit (I checked.) Preserving this behavior does
not seem very useful, though if in the future we need to, adding a check
to libroot is easy enough.

This fixes a deadlock encountered when the usb_rndis driver is unplugged;
the network stack has a removal path that invokes wait_for_thread on
the receive thread, but the function can itself be called from the
receive thread.

Change-Id: Id3639d98a513f2b0f0bacc90d8d27abb5078857b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5310
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2022-05-14 15:26:32 +00:00
committed by waddlesplash
parent 580f28da6d
commit d9694912a7
+2
View File
@@ -2470,6 +2470,8 @@ wait_for_thread_etc(thread_id id, uint32 flags, bigtime_t timeout,
{
if (id < 0)
return B_BAD_THREAD_ID;
if (id == thread_get_current_thread_id())
return EDEADLK;
// get the thread, queue our death entry, and fetch the semaphore we have to
// wait on