Product SiteDocumentation Site

4.5. Other event sources with libtcr

One Unix design principle is everything is a file. As a consequence, a program has only to deal with file descriptors. Linux delivers on that promise even more than its ancestor. The Linux specific system calls signalfd(2), timerfd(2) and eventfd(2) are three excellent examples of that.
Libtcr's event loop can deal with events on file descriptors. We can bridge anything into libtcr's event loop, as long as we can express it as events on a file descriptor.

4.5.1. Unix Signals

Unix signals can be bridged into libtcr's main loop by using the signalfd(2) system call[4]. It is important to set up the signal fd before calling tc_run, so that all worker threads inherit the signal properties from the main execution context. Libtcr's source tar ball comes with the tests/unix_signals.c example program that demonstrates bridging unix-signals to libtcr's main loop.


[4] The signalfd(2) system call is available since Linux-2.6.22. As libtcr requires 2.6.25, this poses no additional constraint.