add thread semaphore and mutex templete