Merged code, set the mutex lock, and set up thread runners.