Jump to content
ashwathgan

wait () vs wait (event)

Recommended Posts

Hi all

 

I noticed a small behavioral pattern of both the above wait statements and I need a small help in understanding it

 

I have a System C thread as follows:

 

SC_MODULE(Task)

{

sc_out<bool> output

....

....

wait ();

...

...

 

SC_CTOR()

{

sensitive << event

}

 

 

 

SC_MODULE(Timer)

{

sc_in<bool> inp [1];

.....

...

 

event.notify(N, SC_NS);

....

}

 

sc_main()

{

 

Task* A = ....

Task* B =.....

 

 

}

 

 

 

Now, the thing I observed during simulation is:

 

1. When I use wait (), first task A thread starts and encounters wait () and then Task B encounters wait (). Thus after the event gets triggered, task B wakes up first and then task A wakes up.

2. But when i use wait (event) instead of wait (), then it happens vice versa. that is, first task A wakes up and then task b wakes up after event is notified from timer mdoule.

 

Why is this behaviour? 

 

 

Thanks in advance for any answer

 

Share this post


Link to post
Share on other sites

Hi,

 

Whenever two processes wait for the same event to appear, they will be triggered and executed in the same delta cycle. The order of execution of processes within one delta cycle is undetermined and implementation (simulator) defined.

This is intended because the execution is actally meant to be parallel (at the same time). If you rely on a specific execution order, you should model this explicitly by triggering the processes explicitly in the intended order.

 

Greetings

Ralph

Share this post


Link to post
Share on other sites

Hi Ralph

 

Thanks for the explanation. I could understand it for wait (event) from your explanation.

 

Is there any reason for order of execution of wait () as it executes in opposite order of wait (event) ??

 

 

 

 

Thanks

Share this post


Link to post
Share on other sites

Hi,

 

I don't think that there is any explicit reason. The actual order depends on the implementation of the simulator kernel. This behaviour is caused by the internal handling of lists of runnable processes, i.e., the answer is somewhere in the simulator's source code.

 

Greetings

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...