Fix bug in pthread lock acquire and release