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

(I asked the question below, but believe to already have found the answer now myself: "sc_get_curr_process_kind()". I will try and work with that.)

I have continuing question on this one.

I have a function that for some complex reasons that take too long to explain here has to execute a wait(0) to allow for an SC_STOP to be executed as soon as possible (ending the current delta cycle). In 99% of my scenarios this function is called from a context of a SC_THREAD and it works just fine. But in very rare cases I need to call this function from outside such a context (some constructor) and in these cases of course I get an error: "Error: (E519) wait() is only allowed in SC_THREADs and SC_CTHREADs"

Is it possible to do something like:

if (bool thisIsThreadContext){
  wait(0);
} else {
  // Do nothing
}

Share this post


Link to post
Share on other sites

sc_get_curr_process_kind() is non-standard.  You can use something like this:

void stop_now()
{
   // Assuming: sc_set_stop_mode( SC_STOP_IMMEDIATE ); to avoid running other processes?
   sc_core::sc_stop();
  
   auto p = sc_get_current_process_handle();
   bool is_thread_or_cthread = p.valid() && p.proc_kind() != SC_METHOD_PROC_;
   if( is_thread_or_cthread )
     sc_core::wait();
}

 

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