Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9082057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:27:57+00:00 2026-06-16T20:27:57+00:00

See the simplified example code here: process job[num_objs]; // assume also, arr_obj1s (array of

  • 0

See the simplified example code here:

    process job[num_objs]; 
    // assume also, arr_obj1s (array of type obj1) and 
    // arr_obj2s (array of type obj2) are arrays of size 
    // num_objs, and the objects define a run() function
    foreach (arr_obj1s[i]) begin
        fork
            automatic int j = i;
            arr_obj1s[j].run(); // these run forever loops
            begin
                job[j] = process::self();
                arr_obj2s[j].run(); // these run finite logic
            end
        join_none
    end

    foreach (job[i]) begin
        wait (job[i] != null);
        job[i].await();
    end

    // How do we ever reach here?

My confusion is that the calls to arr_obj1s[j].run() will never return (they run forever loops) and I don’t quite follow the meaning of that call’s placement outside the begin/end block. Which process is that forever run() executed on, and how can it be that each call to await() will return if some process is running a run() which won’t return?

EDIT: Here is some more information. Posting the full code would be pages and pages, but I hope this extra bit helps.

obj1’s run() function looks like this:

virtual task run;
  fork
    run_a(); // different logically separated tasks
    run_b();
    run_c();
  join
endtask: run

And as an example, run_a looks basically like this (they are all similar):

virtual task run_a;
  // declare some local variables
  forever begin
    @(posedge clk)
    // ...
  end
endtask: run_a

But obj2’s run() function looks basically like this:

virtual task run;
  fork
    run_d(); // different logically separated tasks
    run_e();
  join
endtask: run

And as an example run_d() looks like this:

virtual task run_d;
  while ((data_que.size() > 0)) begin
    // process a pre-loaded queue,
    // data will not be pushed on during the simulation
  end
endtask:run_d
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:27:59+00:00Added an answer on June 16, 2026 at 8:27 pm

    This code fragment looks like it is demonstrating process control so here’s my guess as to what’s going on. There is a group of processes in arr_obj1s and arr_obj2s:

    • Those in arr_obj1s run forever so they only need to be spawned once and forgotten about.
    • Those in arr_obj2s accomplish some task and return, so the parent process needs to know when this happens.
    • All processes have the same parent

    My confusion is that the calls to arr_obj1s[j].run() will never return
    (they run forever loops) and I don’t quite follow the meaning of that
    call’s placement outside the begin/end block

    So all that’s needed to spawn all processes are three lines of code in the fork..join_none block.

    foreach (arr_obj1s[i]) begin
      fork
        automatic int j = i; // Spawns process
        arr_obj1s[j].run();  // Spawns process
        arr_obj2s[j].run();  // Spawns process
      join_none
    end
    

    The join_none keyword indicates that execution will continue after the parallel block completes, thus the entire foreach loop will execute and then the parent process will continue on to the next foreach loop. Further, the join_none also means that the child processes will not start until the parent process reaches a blocking statement.

    However this won’t allow us to detect when the child processes complete, unless they have some sort of shared variable they modify. To get around having to code that, SystemVerilog allows a handle to a process so it can schedule an event when the process completes. It doesn’t, however, provide the ability to get the handle of a single statement. You must use process::self() inside a procedural context to get the process handle. Thus this won’t work right if added directly to the fork-join block.

    foreach (arr_obj1s[i]) begin
      fork
        automatic int j = i;
        arr_obj1s[j].run();
        job[j] = process::self(); // Will return parent process
        arr_obj2s[j].run();
      join_none
    end
    

    To fix this we need to create a new sequential procedural context that we can get the process handle of, then run the function from there:

    foreach (arr_obj1s[i]) begin
      fork
        automatic int j = i;
        arr_obj1s[j].run(); // Spawns a new process for those that don't complete
        begin               // Spawns a new process for those that complete
          job[j] = process::self(); // Saves handle to this begin..end process
          arr_obj2s[j].run();       // Process continues though here
        end
      join_none
    end
    

    The final foreach loop only waits on processes for which we have a handle of. The processes that run forever are ignored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code where I'm returning an array of objects. Here's a simplified
I found a bug, and tracked it down. You can see a simplified example
All code below is a stand-alone working example (greatly simplified) of what I am
Got the simplified array working see below Following up on the complicated array to
Possible Duplicate: C++: Passing pointer variable to function Here is a simplified code snippet
I've simplified my example here massively, so please excuse it if it looks to
See here: http://jsfiddle.net/zYcJm/ The jQuery should be validating each field to check if they
I think it would be quickest to show by example, so here goes a
Note: simplified example.. I've got a page with 1000 table rows. For each row,
So, I have the following object (simplified for sake of example): public class SomeListener

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.