nix icon indicating copy to clipboard operation
nix copied to clipboard

Discussion on the possible implementation of ```SIGEV_THREAD```

Open ChrysoliteAzalea opened this issue 1 year ago • 2 comments
trafficstars

Hello everyone!

On Linux, there is struct sigevent that allows configuring asynchronous notification for some events (such as asynchronous input/output completion, timer expiration or message delivery on POSIX message queue). It supports for types: SIGEV_NONE (nothing happens when event occurs, it has to be polled manually), SIGEV_SIGNAL (a signal is delivered to a process when event occurs), SIGEV_THREAD (a function is called on a designated thread when event occurs), SIGEV_THREAD_ID (a signal is delivered to a thread when event occurs, currently only used by timers). However, nix provides no API for SIGEV_THREAD, and on libc, struct sigevent is exposed in a strange way (instead of exposing an union, it only exposes the "thread ID" part of it). SIGEV_THREAD is provided by glibc in userspace, therefore, I'm proposing to implement it in userspace too. As I see, on Linux, it can be implemented in this way:

  • Reserve a real-time signal for sigevent notifications
  • Create a thread to manage such notifications
  • Create an instance of eventfd or unnamed pipe to send notifications
  • Install a signal handler for immediate notifications, such handler should retrieve the notification information using the si_value() function for siginfo_t structure and send it to a thread
  • Upon receiving a notification, a thread should take action by invoking a user-provided closure

What do you think?

ChrysoliteAzalea avatar Jul 29 '24 14:07 ChrysoliteAzalea