Syntax for Interprocess Communication in the Simulation Collection
I am planning on extending the simulation collection to include interprocess communications (and synchronization) functionality based of Ada task interactions. Note that this is between processes in the simulation collection, not OS processes.
This will allow the model developer to more easily specify process interactions. For examples, resources could be implemented using this functionality.
Entry Definition
Each process entry must be declared in the define-process macro call that defines the process.
(entry (name . arguments))Entry Acceptance
The simplest use of an entry is the accept statement.
(accept (name . arguments)This is an executable statement that will either accept the first (i.e. highest priority) call to name or wait until such a call occurs.
body...)
The select statement allows more control over the selection of entry calls.
(selectEach select clause has one of the following forms:
accept-clause
...)
((accept (name . arguments)The first clause specifies an unguarded accept statement. That is, there are no conditions on its acceptance. The second clause specified a guarded clause. The accept is only active if the guard expression evaluates to true. The third clause is a timeout. The body will be evaluated if none of the alternatives have been accept before the specified (simulated) time has elapsed. The last is an else clause. Its body will be evaluated of no other clause is active.
body ...)
body ...)
((expr)
(accept (name . arguments)
body ...)
body ...)
((delay n)
body ...)
(else
body ...)
[We could also allow a simple accept statement as an alternative when no code is specified other than the entry code itself. That is, allow the following:
(select (name . arguments)Simple examples:
body ...)
(define-process (test)
(entry (abc a b c))
...
(accept (abc a b c)
(printf "a=~s b=~s c=~s~n" a b c))
...)
(define-process (test)
(entry (abc a b c))
...
(select
(accept (abc a b c)
(printf "a=~s b=~s c=~s~n" a b c))
(else
(printf "No entry waiting~n")))
...)
(define-process (test)
(entry (abc a b c))
...
(select
(accept (abc a b c)
(printf "a=~s b=~s c=~s~n" a b c))
((delay 10.0)
(printf "No entry after waiting 10.0 units~n")))
...)
Entry Calls
For now, I will implement an enter statement with a syntax similar to the send statement for classes:
(enter process-instance name . arguments)
A more advanced use is to also allow the select statement with wither a delay or an else clause.
(define my-test (make-process test))
(select
(enter my-test x y z)
((delay 10.0)
(printf "Entry no accepted after 10.0 units~n")))
(select
(enter my-test x y z)
(else
(printf "Entry not open~n")))
I need to decide if it makes any sense to allow other code after the entry call but withn the select.
Since the delay and else clauses don't make sense together (because a delay will always be open), I could combine them:
(elseI will cover possible implementation strategies in a later post.
[(delay n)]
body ...)
Labels: simulation