What is the conceptual difference between a mutex and a semaphore? When would you use a counting semaphore instead of a binary one?

Last updated 5 July 2026

  • A mutex is a lock with ownership: only the thread that locked it may unlock it, and it guards a critical section (code touching shared data).

  • A semaphore is an ownerless signaling counter: any thread can call wait()/signal(), so it suits signaling between threads. A binary semaphore (0/1) resembles a mutex but lacks ownership.

  • Use a counting semaphore when N identical resources exist (e.g. a pool of 5 DB connections initialized to 5, so the 6th thread blocks) or to count bounded-buffer slots.

  • https://www.reddit.com/r/cscareeradvice/new/
  • https://www.reddit.com/r/macbook/comments/1jg7fl6/24gb_ram_enough_for_software_engineering/
  • https://www.reddit.com/r/infosys/comments/1t71add/anyone_received_round_2_mails/
  • https://www.reddit.com/r/cscareeradvice/best/
  • https://www.reddit.com/r/LeetcodeChallenge/
  • https://www.reddit.com/r/infosys/comments/1t71i55/infosys_specialist_programmer_april_26_1st_round/
  • https://www.reddit.com/r/programming/comments/1hqo19u/static_search_trees_40x_faster_than_binary_search/
  • https://medium.com/@avinashkumar808482/operating-system-interview-questions-2026-0db6b4674980
  • https://lmskkhsou.in/eservices/e-Resources/Resources/NEP%20Syllabus%202024/core/BCA_Syllabus.pdf
  • https://growthequityinterviewguide.com/firms/b-capital
  • https://www.interviewbit.com/sre-interview-questions/
All Operating Systems interview questions