Forgot to add the XCloseDisplay in the thread loop.