O'Reilly logo

Linux for Embedded and Real-time Applications, 3rd Edition by Doug Abbott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required