The XLockDisplay is needed so that an error in another thread does not get reported as a failure of XShmAttach.
The XLockDisplay is needed so that an error in another thread does not get reported as a failure of XShmAttach.