zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.66k stars 6.52k forks source link

posix: implement `pthread_kill()` #59943

Open ycsin opened 1 year ago

ycsin commented 1 year ago

There are currently 20 missing POSIX function implementations, pthread_kill() is one of them.

pthread_kill - send a signal to a thread

The pthread_kill() function shall request that a signal be delivered to the specified thread.

As in kill(), if sig is zero, error checking shall be performed but no signal shall actually be sent.

See https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html

See RFC #51211 for more info.

AbhinavMir commented 8 months ago

I'm thinking of doing this in a generic POSIX way, lmk if this sounds right: pthread_t can be converted into an index, with which we find the corresponding k_thread in the posix_thread_pool, and then send a signal to that thread. I'm just wondering how can I "send" a signal to the thread. SIGTERM or SIGKILL are the usual signals, but is there a signal handler in POSIX I can interact with? I see there is one in shell but I don't know if that's where I'm supposed to be looking. Any hints @ycsin ?

cfriedt commented 8 months ago

@AbhinavMir - I have a draft Pr for this already. It might make sense to attempt a different enhancement issue.

AbhinavMir commented 8 months ago

Makes sense, thank you