Subject: Re: Dynamic Process naming/control proposal
From: Kevin Cameron x3251 (Kevin.Cameron@nsc.com)
Date: Mon Aug 12 2002 - 09:17:18 PDT
Here's another (different) go at it...
Proposal:
Amend the syntax to include an identifier for the process and a return value:
process_statement ::== [process_id =] process [: process_name] statement
process_name ::== block_identifier
If the process statement is not named, the process is associated with the nearest
named block in the instance hierarchy. The process_id (pid) is of type int and the
value returned is a positive number which creates a unique pair with the process's
name. A process can query its own pid with the $getpid system task:
int process_id = $getpid();
The allocation of these numbers has no specific order, so a system task is required
to access the processes efficiently in sequence, as well as a task to control the process
e.g.:
always @(spawn) process : subprc my_proc1(); // create new process
always @(kill) begin // kill all the subprc processes
int pid = -2; // Negative value to get first
while (pid != -1) begin // test for last
pid = $next_process(subprc,pid); // get next process id
if (pid > 0) $send_proc(`SIGKILL,subprc,pid);
end
The task $next_process returns the first created process if its second argument is
negative (an invalid pid) and returns -1 if the argument is the pid of the last created
process, the first argument is the name from the process statement.
The task $send_proc sends one of a predefined set of messages to a process, these
include:
0 Test for existance
`SIGKILL Destroy the process
`SIGSTOP Suspend it
`SIGCONT Allow it to continue if suspended
$send_proc returns the int value zero on success and -1 on failure (bad pid). This
matches the Posix threads "kill" function.
Dynamic processes can spawn more processes, so a named parent process will
exist as a "zombie" until its children are dead so that they are reachable by name.
The hierarchical name of a process is its name with its pid in the style of an array
element:
process_name[process_id]
A process's identifier can be reused after it is properly dead.
Since it is sometimes desirable to wait for the completion of a process or group
of processes, the syntax of join should be extended to include a list of processes
or process groups so that it can be used independently of fork:
join_statement ::== join [ : label] {process};
process ::== process_name[[process_id]]
The label of the join statement can be used with disable to cancel waiting. E.g.
done : fork
begin
join : subprc_wait subprc; // wait for sub process completion
disable done
end
@(reset) disable subprc_wait;
join
-------
Notes:
Possible shortcut operations include dropping the pid from $send_proc to control
a group of processes e.g.:
$send_proc(`SIGKILL,subprc,-1); // kill all subprc processes
If associative arrays are brought in from Vera you can use pids as associative
array indices to create process specific data.
Kev.
-- National Semiconductor 2900 Semiconductor Drive, Mail Stop A1-520, Santa Clara, CA 95052-8090
This archive was generated by hypermail 2b28 : Mon Aug 12 2002 - 09:19:35 PDT