There is a API for me to get some data,such as:
int API_func(pointer * data)
the return value is used to judge whether the function is done, and the data will be writen to the pointer address; but if something wrong, the API_func may not get return ,The program may get stuck,so I need a timer to calculate the timer when call the API_func,and once the time over 30s ,I need to send a signal to GUI,so how can I do? I am a green hand ,so I want know how the Master do ? My method is:
Thread_1: main Thread ,call API here,
Thread_2: timer Thread,include a timer function
when Thread_1 call API,send a msg(FIFO) to active the timer function at timer Thread,if the API cant return successed ,the timer at the Thread_2 will overtime ,then send a msg to GUI ?
is any better method ? thank a lot! sorry,i am green hand in stackoverflow,so i dont how to express what I mean: fake code:
Thread_1:
set_timer_flag_on(FILE *time_flag_1)
API_func()
Thread_2:
if (1==check_timer_flag(FILE *time_flag_1))
{
timer_func(set_over_time);
}