tenox7 / ttyplot

a realtime plotting utility for terminal/console with data input from stdin
Apache License 2.0
956 stars 42 forks source link

Fix race condition on clock display (follow-up to #115) #148

Closed edgar-bonet closed 7 months ago

edgar-bonet commented 7 months ago

Thinking hard about this clock issue made me realize there is a race here.

If some event (data, keystroke or signal) is delivered very close to the select() timeout, select() could catch it and return a positive value, even though the timeout is just expiring. This means that select() returning zero is not a reliable way of knowing whether the clock display needs to be updated.

Instead of looking at the return value of select(), update the clock when the seconds have changed.