If you're starting to think about using multiple threads, stop. You don't need to. Structure your event loop as follows:
while (1){
if (XPending(display)){
// get and process next even
}
//handle animation loop
//NOTE: use clock() function defined in time.h. You should also use the CLOCKS_PER_SEC macro
// assume clock_t last, current are defined, and that last has been set
//Also assume that if you decided on 20fps for animation, you calculated at interval of clock ticks, i.e.:
// clock_t interval = (clock_t)((double)CLOCKS_PER_SEC*0.05);
current = clock();
if (current-last > interval){
handle animation
last = current
}
}//while