Semaphore pattern implementation with timeout of lock/unlock operations based on channel and context.