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.
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
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.
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.
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.