I have problem with running function every x second. My application:
create, bind socket,
listen on that socket,
accept all incoming connection and creates a new thread for each of them,
send and receive some data,
and now in loop should send data every 1.5 sec, 5 sec and 10 sec.
I try do this like that(where "time" should be time in milliseconds/nanoseconds):
while(true)
{
if(fmod(time, 1.5)==0)
{
/*sending data*/
}
if(fmod(time, 5)==0)
{
/*sending data*/
}
if(fmod(time, 10)==0)
{
/*sending data*/
}
}
When I use time()
data are sent multiple times per second, because time()
has precision to one second. Could you give me advice what function I need to use to get the time in high precision?
I use Linux
Question 2: How I can end program (perhaps by using any key) when threads running?