On Sat, Jan 30, 2021, 1:58 PM Gregory Nutt <spudan...@gmail.com> wrote:

> > I'm thinking again about this. Why wouldn't it be possible to make
> functions
> > using SIGEV_THREAD (such as timer_settime) create a pthread behind
> > the scenes (only the first time a SIGEV_THREAD is setup)? The underlying
> > watchdog would go to a handler that posts a semaphore/condition variable
> > that the helper thread is waiting on. When this thread unblocks, it
> calls the
> > user handler directly.
> >
> > The thread would be created per-process in KERNEL mode, so that shouldn't
> > be a problem (inside same address space as user handler). I suspect the
> > unblocking of the thread should also be possible in multi-process somehow
> > (named semaphore?).
> >
> > This is essentially what I'm doing myself around a call to timer_settime.
> >
> > Best,
> > Matias
>
> I think a proper approach would be to see how Linux/GLIBC accomplish
> this.  I think that would give you some ideas for proper implementation.
>

This is actually fairly in line with how the Musl libc implements this (at
least from a quick look).  There are a few important details in there, but
it looks quite clean.

http://git.musl-libc.org/cgit/musl/tree/src/time/timer_create.c

While Musl is usually not as fast as glibc, I find the implementations
usually more straight forward and smaller code size.

>

Reply via email to