Re: SDL-News: Request for Help: Initialisation of Pids


Subject: Re: SDL-News: Request for Help: Initialisation of Pids
From: Rick Reed TSE (rickreed#tseng.co.uk)
Date: Fri Jul 14 2000 - 18:18:33 GMT


Become an SDL Forum Society member <http://www.sdl-forum.org/Society/members.htm>
The originator of this message is responsible for its content.
-----From Rick Reed TSE <rickreed#tseng.co.uk> to sdlnews -----

Reji P Rajesh at rejip#cdotb.ernet.in wrote on 13/07/2000 17:41:

> I am working in SDL for quite a some time. I am
> not able to find a way to send signal to a process of the same instance.
> That is I have two instances of process A. (let it be A1 and A2). How
> to send signal from A1 to A2.
> I didn't use create request in my SDL model.

This can be achieved in SDL (and therefore tool and implementation
independent) by introducing another process (B) with one instance.

The start transition of each instance of A can send a signal to B. B can
send a signal to the each instance of A, when it has received signals from
both instances of A. The signal from B can contain the Pid of the other A
instance derived from SENDER. After sending a signal to B, each A instance
can wait for the signal from B and save all other signals, before entering
its normal processing.

In this way, the addressing is set up during the initialisation of the
system and has no overhead on subsequent processing.

Here is some code in SDL/PR to do this:

BLOCK to_Other;
  SIGNAL
  announce,/* to B which derives Pid from SENDER */
  setpid(pid,integer);
  /* Pid of process, process 'index'*/
  /* integer not used in this example */
  SIGNALROUTE FROM A TO B WITH announce;
  SIGNALROUTE FROM B TO A WITH setpid;
  PROCESS A (2,2) REFERENCED;
  PROCESS B (1,1) REFERENCED;
ENDBLOCK to_Other;
  
PROCESS A;
  DCL othera pid;/* Pid of Other A process*/
  START;
  OUTPUT announce; /* send to B */
  NEXTSTATE waitpid;
  STATE waitpid;
    SAVE*; /* Save everything except .. */
    INPUT setpid(othera); /* set pid of other A process */
      NEXTSTATE ready;
  ENDSTATE waitpid;
  
  STATE ready; ENDSTATE ready;
  /* rest of process here */
ENDPROCESS A;
  
PROCESS B;
  DCL pid1,pid2 pid;
  START;
  NEXTSTATE getpid1;
  STATE getpid1;
    INPUT announce;
      TASK pid1:=SENDER;/* A pid of one A process */
      NEXTSTATE getpid2;
  ENDSTATE getpid1;
  STATE getpid2;
    INPUT announce;
      TASK pid2:=SENDER; /* A pid of second A process */
      OUTPUT setpid(pid2,2) TO pid1;
      OUTPUT setpid(pid1,1) TO pid2;
      NEXTSTATE finished;
  ENDSTATE getpid2;
  STATE finished; /* could do other things here */
  ENDSTATE finished;
ENDPROCESS B;

This scheme can be extended to any number of initial A processes as follows
(using the integer in setpid). Since the number of initial A processes is
fixed (it as is assumed there are no process create requests) this is known
and can used to count the number of signals expected. The B process can have
a state that receives an announce signal from an A process an stores the pid
in an array using the count of the number of announce signals as an index.
If the maximum announce signals has not been received the B process returns
to the state waiting for the next announce.

When the maximum number of announce signals has been received, the B process
can send each A process a setpid(Apid,index) signal for each element in the
array (or the whole array could be sent in one signal to each A process).

After sending the announce the A process waits for the setpid signals (or
one array in a signal), counting the number of signals received in the case
of setpid signals.

I have successfully used this scheme in more than one project.

--
Rick Reed - rickreed#tseng.co.uk
Tel:+44 1455 55 96 55 Fax:+44 1455 55 96 58 Mob.:+44 7970 50 96 50

-----End text from Rick Reed TSE <rickreed#tseng.co.uk> to sdlnews ----- For extra SDL Forum Society benefits, join at <http://www.sdl-forum.org/Society/members.htm>



This archive was generated by hypermail 2a23 : Thu May 09 2013 - 16:05:49 GMT