Alex Rivera | Logout

How to set a timeout for a function in C?

Asked 2011-10-12T10:21:08.373
16

I have a requirement that I have to give xx ms to execute a function. After xx ms I have to abort that function. Please help me how to implement it in C.

c
Edit
Report

1 Answer

2
->include time.h 
->take two variable for start time & current time of type time_t
like time_t start_time,current_time
-> take start time 
   time(&start_time);
now in while loop continuisly check for 
   time(&current_time)
   difftime(current_time,start_time)
if difftime's return value is 15ms break while loop & close your program 
answered 2011-10-12T10:59:06.383

Your Answer