[SOLVED] How to restart a thread at midnight?

Hello,

I am running Ubuntu 11.04.

I have an application that downloads data from the remote web server. This web server shuts down for maintenance at midnight for about ten minutes. So I need to disconnect from the server at 11:55pm and connect again at 12:05am. I use sockets so to disconnect I need to logout and close the socket, and to re-connect I need to open socket and logon. The part of my application that downloads data runs in its own thread.

So I need to stop the thread at 11:55pm and start at 12:05am. How do I do that efficiently?
If I use polling for system time until I get 11:55pm I am afraid polling will impede performance.

Any suggestions please. TIA!
Last edited on
cron ?
cron - that is for solution 1) to restart whole application - thx!

Any suggestions for solution 2) : to efficiently restart a thread at a certain time?

what about sleep?
what about sleep? -- meaning I have to run sleep(60) in separate thread and check for system time?


I edited my original post, I do not want to restart the whole application, just the thread that downloads data.

Last edited on
closed account (3hM2Nwbp)
You might consider looking into boost's deadline_timer asynchronous implementation.

http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/reference/deadline_timer.html

* Have you profiled a polling solution yet? If polling is the simplest, most easily maintained solution, then IMO it would be worth it to implement it and benchmark it against your needed performance criteria.
Last edited on
I'll use setitimer or sleep(60) in separate thread, I'll see what's easier and better.

Thank you for suggestions.

[SOLVED]
Topic archived. No new replies allowed.