implement semaphores and statistics