Add XInitThreads and the corresponding XLock and Unlock