The program has a cycle and a separate function in which the data is synchronized (a long operation, it takes more than 10 seconds). The loop uses a timer that starts this function after it expires. But while the function is executed, the cycle is worth it. Here is a sample program:
int sync(struct stack **data) { // обновляем массив data из файла } int main() { struct stack *data=NULL; struct itimerspec t={0}; struct timeval timeout={0,0}; int timerfd; uint64_t exp; t.it_value.tv_sec=50; t.it_interval.tv_sec=0; if ((timerfd=timerfd_create(CLOCK_REALTIME,TFD_NONBLOCK))==-1) {return EXIT_FAILURE;} if (timerfd_settime(timerfd,0,&t,0)==-1) {return EXIT_FAILURE;} while (TRUE) { if (read(timerfd,&exp,sizeof(uint64_t))>0) { sync(&data); } // проверка данных в массиве data и какие либо действия } }
Is it possible to somehow run the sync function, say on the background, so that the loop runs on?