How can i implement fork-join() functionality without using the fork join construct in system verilog

This question was asked during an interview. Can you help me with question. I tried putting the threads in two different initial blocks but couldn’t get the required result.

this is a sample of the code i tried:

module tb();

initial
process(a);

initial
process(b);

endmodule

The above can lead to a race condtion and will not get the desired result. Can you suggest some other way to achieve it.

In reply to Ammu89:

Since the restriction is on usage of fork join , I assume you are free to use
fork join_any and fork join_none



  initial   begin

      fork

         begin
            
           #2 ; 
          $display("#2 Done") ;

         end


         begin

          #4 ; 
          $display("#4 Done") ;

          end

      join

         $display("Fork  join  completes ");
   
    end
 

The above fork join functionality can be achieved via ::



  initial   begin

      fork

         begin
            
           #2 ; 
          $display("#2 Done") ;

         end


         begin

          #4 ; 
          $display("#4 Done") ;

          end

      join_none
          
          wait_fork ;
         $display("Fork  join  completes ");

      end
 

Actually the question mentioned none of the fork-join, fork-join any Or fork join-none constructs should be used.

Thanks

In reply to Ammu89:

We can’t answer the question without knowing what the desired results are.

In reply to Ammu89:


module test;
  
  event event_h;
  
  initial
    begin
      wait(event_h.triggered);
      $display("[%0t] Executing process 1",$stime);
    end
  
  initial
    begin
      wait(event_h.triggered)
      $display("[%0t] Executing process 2",$stime);
    end
  
  initial
    begin
      #1;
      -> event_h;
    end
  
endmodule

Just a try, Not sure whether this is an appropriate answer.

Hi Dave,

The questioner asked only this much to me.
Without using fork-join constructs implement its functionality.

Thank you sai_pra99.
Solution is as best as possible, with only one problem.

For your code the simulated out put look as follows:
[1] Executing process 1
[1] Executing process 2

if the same was in fork-join the output would look as follows:
[0] Executing process 1
[0] Executing process 2

There is a clock cycle delay happening as we wait for the event to trigger. If there is a way to avoid that also, the solution is perfect.

thanks

In reply to Ammu89:
Yeah just remove that #1 delay, you get the desired result.I just added it without any intent.

In reply to Ammu89:

You can also use semaphore to sync up 2 threads or mailbox.

But to me, it is not good way that interviewer asks not to use language all features. This means that interviewer does not spend time to prepare good question.
It is like drive the car without using acceleration.
Think twice before accepting the offer.

In reply to haykp:

Love that analogy about driving a car; I’ve been searching for something like that.

Sometimes it’s more about about making sure you have enough information to attempt a solution rather than actually providing a solution.

A car can’t go from stationary to moving with acceleration. Did you really mean “without putting pressure on the accelerator pedal?”

If someone or something pushes my car from behind, or coast down a hill, is that still considered “driving”? Or does the car need to be self-propelled?

Back to the fork-join question, there are an infinite number of way to write code with a fork-join, and for some of those, removing the fork would have no change in the behavior.

initial fork
         $display("hello");
        join

Removing or replacing the fork/join with begin-end would not change the behavior. So I would have asked for a particular example of fork-join usage that they wanted implemented without using fork-join.