Question about '#0'

Assume following 3 blocks begin at the same simulation time, will it be deterministic that processC is exectued after processB and processB is exectued after processA?

blk1:
begin
processA;
end

blk2:
begin
#0;
processB;
end

blk3:
begin
#0;
#0;
processC;
end

It is described in IEEE 1364: "An explicit zero delay (#0) requires that the process be suspended and added as an inactive event for the current time so that the process is resumed in the next simulation cycle in the current time", but still, I am not very sure what will happen if there are 2 '#0'. thanks!
1 Like

To say that execution order within the same simulation time is deterministic is very dangerous to rely on.

The way an event driven simulator works, all active events are executed until there are no more active events, and then the list of inactive events becomes the active list. That process repeats until there are no more active or inactive events. Each repetition through that loop is called a delta cycle and #0 is used to delay a process to the next delta cycle. If there are 2 #0’s the process will suspend and resume twice through the loop.

So if the three blocks begin at the same simulation time and the same delta cycle, then the processes will execute in the order you specify. There are many reason for not writing code that does this. All someone has to do is insert a #0 somewhere else to prevent the blocks from executing in the same delta cycle and your ordering no longer becomes deterministic. And there is no easy way to track how many #0’s there in a process without careful examination of the code. Many people resort to writing “repeat (10) #0;” in the hope that it will introduce enough delta cycles to make sure what follows goes last. That can really slow your code down.

A much better way is to use named events, semaphores, or mailboxes to synchronize processes.

1 Like

In reply to dave_59:

Hi dave,

As you stated what the “delta cycle” is : "The way an event driven simulator works, all active events are executed until there are no more active events, and then the list of inactive events becomes the active list. That process repeats until there are no more active or inactive events. Each repetition through that loop is called a delta cycle"

So, can one say that how many delta cycles could be in a single time step?

And Is there any relation of delta cycle with ordered event regions(Preponed,Pre-Active,Active,etc.) as far as active events and inactive events you mentioned?

Thanks in advance.

1 Like