Either or both can start other threads. Each thread gets its own stack. The program is not logically correct, and it also has performance problems. N, then calls itself recursively in parallel to sort each half. It then merg es the sorted halves together.
Semaphores act as primitive objects which perform synchronizations of several sorts.
Using semaphores, critical sections which execute in mutual exclusion can be built. In turn these allow new atomic actions to be defined, which can then perform any required form of synchronization. A semaphore, S, is an object with two components, one an integer value , the other a queue, waiters, of threads waiting on this semaphore. The semaphore constructor sets waiters empty and value to a supplied non-negative integer. All semaphore operations are atomic.