Once you know a critical section needs protecting, you need a tool to do it. A mutex is a lock owned by the thread that took it, used to guard one shared resource. A counting semaphore tracks a number of free units or signals between processes, so it also handles ordering like "B runs after A". "Mutex vs semaphore" is a favourite interview question, and the key difference is ownership.