It is very common for real-time applications to have tasks that need to run periodically, for example to scan inputs or to generate regular outputs. A crude solution is to use a processing loop with a sleep at the end, but the periodicity will vary as the execution time varies. To create accurate periodic tasks you need to use timers. In this article I will show how timers work in Linux, especially with regard to multi-threaded applications.
Threads show up in process listings with the same name as their parent process which makes them hard to tell apart (this article describes how to list threads). It would be much nicer if the threads were given meaningful names such as “input_task”, “alarm_thread” and so on. In this short note I will show how it is done.
Since the introduction of the Native POSIX Threads Library (NPTL) threads have become rather elusive. They don't show up in the default process listing using the ps command and if you are using the ps applet from Busybox they don't show up ever. In this note I will show how to display thread information using the full ps program and how to do the same thing in a shell script if you don't have it.
The mutex is a simple little thing with one job to do: ensure mutual exclusion between threads. Yet Linux has up to 16 variations of the mutex, depending on which versions of the kernel and C library you have (see the table at the end). In this article I will try to explain why there are so many and how they affect your programs.