Move locking and thread ID functions into new files lock.c and thr_id.c,