I always notice people have different reactions to different ways of creating a timer in Unix.
I know a few different ways that I could make an event execute every X seconds within Unix:
- you can do a polling thread - pthread_t with sleeps;
- you can do a select() with a timeout;
- and I guess you can use the OS in a few other ways.
Can someone provide some sample code with the "best" or most efficient way to do a timer and a description of why it is the best? I'd like to use the most efficient mechanism for this but I'm not sure which one it is!
For our purposes, just pretend you're printing "Hello, World!" once every 10 seconds.
Note: I don't have TR1, Boost, etc. on this system, so please keep it to straight-up C/C++ and Unix system calls.