In clock_func() it is necessary to read the timer fd, or it will stay readable, and the event loop will call the function again. That causes an endless loop.