added spinlock, semaphore improved