Protected Types: Wait and Private Signals
Requirement Summary
To implement
Semaphore data structures a protected type needs a means to stop until a resource is available.
See also
ISAC Issue 2109
Protected Types with Wait Statements
In order to implement Get within a protected type, requires support for wait statements within a protected type procedure method. This is some what complicated by a protected type guaranteeing mutual exclusive access to the internals of the protected type. When a wait statement is encountered, the mutual exclusive access must be dropped, as otherwise, there would be no way to release the semaphore. This means when the method wakes up from a wait, either it is an error (detected by the compiler) or erroneous (meaning an error that is not detected by any compiler) for the method to access local variables (ones declared in the method) before they are updated with new values or local variables must be re-initialized to either the same value they had on entry to the method or the left-most value of the type. Another alternative is to disallow local variables in a procedure method that calls wait. Since this method can call other procedures which can have local variables, this may be an acceptable conservative simplification of the requirements.
In addition, to satisfy the nature of common structures such as Semaphores and Mailboxes, if there are multiple calls to a protected method (called from different processes/threads), then there needs to be means to wake up wait statements in the order they were received (ie: semahpore and mailbox waiting queues is first in, first out). Furthermore, if there are waits statements currently suspended and a signal changes within these wait statements, these methods must be run before new methods of the protected type may run. Needs some type of "Now Serving" value.
Private Signal/Event Class object in protected type body
A semaphore Get needs some sort of a wake-up event. In an architecture, this would be a signal. The issue with a signal is one must trace drivers back to their source. Inside the protected type body, we do not want to create a persistent source of a signal. Instead we want to drive a signal and use register kind properties to retain its value after the method exits. Alterantely a new object with deposit type (no drivers) that has events like a signal and signal type update rules (meaning update on the next simulation cycle/delta cycle to ensure safe execution).
'transaction and declaration of signals in procedures (and processes)
The attribute 'transaction creates an equivalent signal. Currently its usage in procedures is forbidden. However, in particular with respect to creation of semaphores, it would be useful if not necessary to be able to use "wait on signal_name'transaction" rather than "wait on signal_name". The issue being what happens with a multi-key semaphore when one processes does a put during the same delta cycle in which another does a get - both for the same amount. If a signal based algorithm were used, then there would not be an event on the signal.
Wait Statements on Private Variables
There are potential interesting interactions between methods, waits, and delta cycles. Would it be reasonable to consider waking up wait statements within a method based on a protected type variable? In the above, how does one resolve the timing between the semaphore count signal and the semaphore count variable? Maybe a conjunction of the signal and variable need to be used?
Questions
General Comments
Important for testbenches
Supporters
Add your signature here to indicate your support for the proposal
-- JimLewis - 2014-12-03
--
Brent Hayhoe - 2014-12-22
--
MortenZilmer - 2015-01-21
--
PatrickLehmann - 2016-02-19
- SAB 15: Semaphore data structure. Implement in a library.
- Provides: New(#keys), Get(#keys), Put(#keys), Try_Get(#keys)
- Use Protected type is the key counter & implement the rest using regular functions and procedures.
- try_get is a function, the others are procedures.
- New returns the handle to the object - could be an integer index value
- What do we need it for? Multiple items trying to use one resource. Software - network access to a printer
- Typically only one key. Default for put and get is 1 key.
- Waiting queue is first in, first out.
- Should be deterministic.
Topic revision: r6 - 2020-02-17 - 15:34:57 -
JimLewis