title: Scheduling of Process(s) waiting for Semaphore
body: <p>It is always said when the count of a semaphore is 0, the process requesting the semaphore are blocked and added to a wait queue.<br>
  When some process releases the semaphore, and count increases from 0->1, a blocking process is activated. This can be any process, randomly picked from the blocked processes.</p>
  
  <p>Now my question is:<br>
  If they are added to a queue, why is the activation of blocking processes NOT in FIFO order? I think it would be easy to pick next process from the queue rather than picking up a process at random and granting it the semaphore. If there is some idea behind this random logic, please explain. Also, how does the kernel select a process at random from queue? <strong>getting a random process that too from queue is something complex as far as a queue data structure is concerned</strong>.<br>
  tags: <strong>various OSes</strong> as each have a <strong>kernel</strong> usually written in <strong>C++</strong> and <strong>mutex</strong> shares similar concept</p>