XShutdown (i.e. the "eXtended Shutdown" and "Restart Desktop" features) resides entirely in the src\startshut\shutdown.c file.

XShutdown starts two additional threads to close all the windows. This is described in detail in the "XWorkplace Internals" section of the XWorkplace User Guide. I have also tried to put plenty of comments into the sources.