Implementing user mode timers
Posted: Wed Mar 10, 2021 10:32 am
How is this best done?
In kernel mode it's rather easy. My logic is part of the preemption timer which can either preempt the running thread or trigger a timer. However, the callbacks for kernel mode timers are asynchronous and cannot be used directly to implement user mode timers.
Also, the timers would be started in user-mode, and so ideally some user mode area would link timers in expire order and then the head element would do a wait until syscall which uses kernel mode timers.
A possible solution might be to start a new thread for timers and let it wait until the head element expires. When there are no timers, the timer thread could be terminated.
I think in Posix this is part of libc, but since I want to be able to use this without involving the runtime library (it would eventually be part of the new file API to force flush of files), and so it would need to be handled by the executable loader.
In kernel mode it's rather easy. My logic is part of the preemption timer which can either preempt the running thread or trigger a timer. However, the callbacks for kernel mode timers are asynchronous and cannot be used directly to implement user mode timers.
Also, the timers would be started in user-mode, and so ideally some user mode area would link timers in expire order and then the head element would do a wait until syscall which uses kernel mode timers.
A possible solution might be to start a new thread for timers and let it wait until the head element expires. When there are no timers, the timer thread could be terminated.
I think in Posix this is part of libc, but since I want to be able to use this without involving the runtime library (it would eventually be part of the new file API to force flush of files), and so it would need to be handled by the executable loader.