Jump to content
ankushKumar

function with wait

Recommended Posts

Hello all,

 

I have doubt regarding use of c++ function inside systemc threads.

It is said that a normal c++ function which is declared in a class inherting systemc module and called  inside the thread of that class shall be executed based  c++ kernel simulation not on the basis of systemc scheduler therefor it won't  wait for an event or time if introduced in it. Is that true ? But in my code nothing as such is happening the function is waiting for time introduced in it.

 

Regards.   

Share this post


Link to post
Share on other sites

See Note 4 in 5.2.11 of the LRM

 

NOTE 4—Function wait can be called from a member function of the module itself, from a member function of a
channel, or from any function subject only to the rules of C++, provided that the function is ultimately called from a
thread or clocked thread process.

 

 

Alan

Share this post


Link to post
Share on other sites

See Note 4 in 5.2.11 of the LRM

 

 

Alan

hello

i got that but would like to know what exactly happening.

 

see

 

class A:public sc_module{

public :

           A(){

                SC_THREAD(funcA);

           }

           SC_HAS_PROCESS(A);

           void funcA(){

                funcB();

           }

           void funcB(){

                wait(100,SC_NS);

           }

}

 

Now funcA is a thread thus registered with the systemc scheduler.

what about funcB it is a C++ based function having wait whether it gets registered with systemc kernel since a normal c++ function cannot suspend.

Share this post


Link to post
Share on other sites

funcB is still called in the context of the SC_THREAD.

 

When you declare an SC_THREAD, the threading library (pthreads or quickthreads) keeps track of the a local stack pointer and local stack variables for that thread. When you call wait(), it pushes the state of the processor onto the stack at that point - it doesn't matter if you're inside lots of nested function calls, as long as you're in the context of an SC_THREAD, the wait() method works.

 

wait() is a method of the sc_module base class.

 

regards

Alan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×