# Semaphore: process returning more keys than got for processing

**URL:** <https://verificationacademy.com/forums/t/semaphore-process-returning-more-keys-than-got-for-processing/30212>\
**Category:** SystemVerilog\
**Tags:** semaphore-keys, SystemVerilog\
**Created:** [December 11, 2014, 7:11am UTC](https://verificationacademy.com/forums/t/semaphore-process-returning-more-keys-than-got-for-processing/30212 "2014-12-11T07:11:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepa.djdoll](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/dfb087/32.png) [@deepa.djdoll](https://verificationacademy.com/forums/u/deepa.djdoll)\
**Post date:** [December 11, 2014, 7:11am UTC](https://verificationacademy.com/forums/t/semaphore-process-returning-more-keys-than-got-for-processing/30212/1 "2014-12-11T07:11:05Z")

</div>

1. I “new” a semephore with 2 keys
2. Two processes P1, P2. P1 needs two keys also P2 needs two keys for its process to start
3. P1 gets 2 keys but when I returned 5 keys from P1, [b]it did not give my any compile/runtime error.

Question:  
1)How a process can return 5 keys when it has got only two keys?  
2)Why it did not give me any compile/runtime error while returning the keys?  
3)For P2 are there now 5 keys available or 2 keys available which we “new” while creating the semaphore?  
Please carify.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [December 11, 2014, 8:47am UTC](https://verificationacademy.com/forums/t/semaphore-process-returning-more-keys-than-got-for-processing/30212/2 "2014-12-11T08:47:49Z")

</div>

A semaphore does not manage the number of keys; it only manages handing out of keys that it has.  
Think of a bank with a set of coins. When you construct the bank, the new() constructor deposits an initial set of coins. Then people stand in line waiting to get() a certain number of coins, while other people come to put() coins in the bank. There are many different ways to use a semaphore, but all of them require the user to manage the number of keys that are get() or put().

A mailbox, on the other hand is constructed with a maximum size.

---

<div class="post-metadata">

**Author:** ![deepa.djdoll](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/dfb087/32.png) [@deepa.djdoll](https://verificationacademy.com/forums/u/deepa.djdoll)\
**Post date:** [December 11, 2014, 9:24am UTC](https://verificationacademy.com/forums/t/semaphore-process-returning-more-keys-than-got-for-processing/30212/3 "2014-12-11T09:24:59Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/semaphore-process-returning-more-keys-than-got-for-processing/30212/2):_

Thnx, now understood the concept clearly.
