Chapter 9

Posix Threads

Linux is only free if your time has no value.

Jamie Zawinski

The thermostat that we developed in the last chapter isn’t very practical because the operating parameters, setpoint, limit, and deadband are hardcoded into the program. Any practical thermostat would make these parameters user adjustable. In this case, we might invent a simple command protocol to change the parameters through the console.

How might we implement such a process? Back in the old DOS days, we might have used the function kbhit() to poll the keyboard for activity. But Linux is a multitasking system. Polling is tacky. What we need is an independent thread of execution that waits for a line of text on the console, parses the line, and acts on it.

Get Linux for Embedded and Real-time Applications, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.