【SystemVerilog】Fine-grain process control

本文介绍了一种内置进程类,允许一个进程访问和控制另一个进程。文章详细解释了进程的状态、如何创建和使用进程对象,以及提供了关键进程操作的示例,如终止、等待和挂起等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A process is a built-in class that allows one process to access and control another process once it has started.
Users can declare variables of type process and safely pass them through tasks or incorporate them into other

objects. The prototype for the process class is as follows:

 

class process;

 

typedef enum { FINISHED, RUNNING, WAITING, SUSPENDED, KILLED } state;

 

static function process self();
function state status();
function void kill();
task await();
function void suspend();
function void resume();
function void srandom( int seed );
function string get_randstate();

function void set_randstate( string state );

 

endclass

 

Objects of type process are created internally when processes are spawned. Users cannot create objects of
type process;
attempts to call new shall not create a new process and shall instead result in an error. The

process class cannot be extended. Attempts to extend it shall result in a compilation error. Objects of type

process are unique; they become available for reuse once the underlying process terminates and all

references to the object are discarded.

 

The self() function returns a handle to the current process, that is, a handle to the process making the call.

The status() function returns the process status, as defined by the state enumeration:

 

FINISHED means the process terminated normally.
RUNNING means the process is currently running (not in a blocking statement).
WAITING means the process is waiting in a blocking statement.
SUSPENDED means the process is stopped awaiting a resume.

KILLED means the process was forcibly killed (via kill or disable).

 

The kill() function terminates the given process and all its subprocesses, that is, processes spawned using
fork statements by the process being killed. If the process to be terminated is not blocked waiting on some
other condition, such as an event, wait expression, or a delay, then the process shall be terminated at some

unspecified time in the current time step.

 

The await() task allows one process to wait for the completion of another process. It shall be an error to

call this task on the current process, i.e., a process cannot wait for its own completion.

 

The suspend() function allows a process to suspend either its own execution or that of another process. If
the process to be suspended is not blocked waiting on some other condition, such as an event, wait
expression, or a delay, then the process shall be suspended at some unspecified time in the current time step.

Calling this method more than once, on the same (suspended) process, has no effect.

 

The resume() function restarts a previously suspended process. Calling resume on a process that was

suspended while blocked on another condition shall resensitize the process to the event expression or to wait
for the wait condition to become true or for the delay to expire. If the wait condition is now true or the
original delay has transpired, the process is scheduled onto the Active or Reactive region to continue its
execution in the current time step. Calling resume on a process that suspends itself causes the process to

continue to execute at the statement following the call to suspend.

 

initial procedure, always procedure, or fork block from one of those procedures.
The following example starts an arbitrary number of processes, as specified by the task argument N. Next,
the task waits for the last process to start executing and then waits for the first process to terminate. At that

point, the parent process forcibly terminates all forked processes that have not yet completed.

 

 

task automatic do_n_way( int N );

 

 

process job[] = new [N];

 

foreach (job[j])

   fork

      automatic int k = j;

      begin 

          job[k] = process::self(); 

          ... ;

      end

   join_none

 

foreach (job[j]) // wait for all processes to start

    wait( job[j] != null );

job[1].await(); // wait for first process to finish

foreach (job[j]) begin

    if ( job[j].status != process::FINISHED )

        job[j].kill();

end

endtask

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值