How to periodically execute a function in C ??

Most operating systems have an equivalent.

In Windows GUI land it's GetMessage(), in Winsock[2] it's select(), also WaitForMultipleObjects().

Palm programs have a message loop at the heart of any program.

What ever you are doing, do it efficiently, even if you are doing nothing, do nothing as efficiently as possible.

So, I'm looking at WaitFor.c in the xorg-server/os source files. I see where it selects it's clients, but I don't see where it selects anything triggered off of a clock. I also see time() checks in the source, but it looks like the piece is the screen saver manager.

I also found selects in hw/xfree86/common/xf86Events.c, but that looks like stuff used to wake up from the screen saver.

I haven't found what I'm looking for yet. What I'm trying to find is a, hopefully very platform independent way of executing a function at regular intervals, without using a sleep anywhere in the program. Something like JavaScripts setTimeout() and setInterval(). And, it's got to be thread safe.

I'm sure the x server does this, but I don't know exactly where to look.
Any tips?

Start at

XtAppAddTimeout(app,interval,do_stuff,data);

internally it builds a list of events to run at certain times, and uses the earliest time of an event to calculate the timeout to use in a select/poll statement.

The timed event will run during an event loop

XtAppMainLoop(app);

That's getting to what I'm after. I've never seen the innards of the WaitForMultiple... stuff (though I make pretty good use of the api's). I've never used the used the motif libraries. I really just want to know how to do the select. So, I'm digging through Motif now looking for the guts of the XtAppAddTimeout / XtAppMainLoop. I get about a thousand hits for the XtAppMainLoop, but none on XtAppAddTimeout. Any idea where the actual select is?

"Motif" sits on top of "Intrinsics" (libXt) which sits on top of "X11".

You need to be looking in Intrinsics, say in xfree86 source or x.org source.