Skip to content

Commit 084132e

Browse files
andyrossChristopher Friedt
authored andcommitted
kernel: Add z_thread_wake_joiners() utility
POSIX has a somewhat odd behavior that when you call pthread_detach()[1], it is supposed to synchronously wake up anyone currently joining the thread. That isn't a Zephyr kernel behavior[2], so it needs to be exposed. The implementation is as simple as it sounds. This is minimal: we don't try to keep any state around to inform the k_thread_join() call whether the thread actually exited or if this new function was used. That has to be provided by the outer layers (pthreads already do this). [1] Which tells the OS/platform that it can clean the thread up as soon as it exits and doesn't have to keep it around as a zombie until someone calls pthread_join() on it. [2] Because... why!? Not needing to keep a thread around for joiners isn't the same thing as disallowing joins! Signed-off-by: Andy Ross <[email protected]>
1 parent 22bf59f commit 084132e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

kernel/include/ksched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ void z_ready_thread(struct k_thread *thread);
6464
void z_requeue_current(struct k_thread *curr);
6565
struct k_thread *z_swap_next_thread(void);
6666
void z_thread_abort(struct k_thread *thread);
67+
void z_thread_wake_joiners(struct k_thread *thread);
6768

6869
static inline void z_pend_curr_unlocked(_wait_q_t *wait_q, k_timeout_t timeout)
6970
{

kernel/sched.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,13 @@ static void end_thread(struct k_thread *thread)
17291729
}
17301730
}
17311731

1732+
void z_thread_wake_joiners(struct k_thread *thread)
1733+
{
1734+
LOCKED(&sched_spinlock) {
1735+
unpend_all(&thread->join_queue);
1736+
}
1737+
}
1738+
17321739
void z_thread_abort(struct k_thread *thread)
17331740
{
17341741
k_spinlock_key_t key = k_spin_lock(&sched_spinlock);

0 commit comments

Comments
 (0)