[threading] Wrap the threads lock with cooperative coode.