Added semaphore management to queues; implement basic command loop (no dispatching yet)