Refactored the pthread code for X11 platforms.