I want to make a function that executes at specified time interval, lets say at every 30 seconds, when the time is something like this: 12:37:00.000000, 12:37:30.000000, 12:38:00.000000
Now the easy approach would be to create a thread running a function that has a while loop that has a sleep(30) at the end, thus waiting 30 seconds at the end. My application will be running 24/7, and in time, lets say maybe 2-3 hours from the start, the real time at which it will be executing that function would be X:X:00.5 or X:X:33.5(because there is a lot of code above that sleep(30)), thus delaying my work by a small margin every 30 seconds, and in few hours, by a pretty big margin.
What I'm searching for is a elegant method to set like an alarm that triggers at every 30 seconds, but always exactly 30 seconds, no more, no less, since precision is a must.