Can a thread hold multiple semaphore keys?

In reply to Thobiyas:

Each instance of a semaphore holds a count of keys. A thread can add or subtract from that count; it doesn’t hold anything.

Thread_2 hangs because it tries to get(1) a third semaphore key which never gets added. Perhaps you meant that to be put(1) instead? Thread_1 hangs because the keycount is 0 at time 10.