Jump to content

Process deadlock situation


rahuljn

Recommended Posts

Hi Guys

 

WIth the below program I was expecting the simulation will be blocked indefinitely but it exits and total simulation time is 0

 

Can someone tells me why it didn'y gets blocked indefinitely ?

 

#include "systemc.h"

SC_MODULE(event_trial){
    public:
    sc_event p1,p2;
    SC_CTOR(event_trial) {
        SC_THREAD(process1);
        SC_THREAD(process2);
    }

    void process1(){
        while(1){
            wait(p2);
            p1.notify();
        }
    }

    void process2(){
        while(1){
            wait(p1);
            p2.notify();
        }
    }
};

int sc_main(int , char**){
    event_trial et("et");
    sc_start();
    cout<<"Simulation time : "<<sc_time_stamp().value()<<endl;
 }

Link to comment
Share on other sites

A quick read shows that this behavior is defined in the standard document, section 4.3.4.5

 

 

When function sc_start is called without any arguments, the scheduler shall run until there is no remaining
activity, unless otherwise interrupted. In other words, except when sc_stop or sc_pause have been called or
an exception has been thrown, control shall only be returned from  sc_start when the set of runnable
processes, the set of update requests, the set of delta notifications and time-outs, and the set of timed
notifications and time-outs are all empty. On return from sc_start, the implementation shall set simulation
time equal to the time of the most recent event notification or time-out.

Link to comment
Share on other sites

Hi Guys

 

WIth the below program I was expecting the simulation will be blocked indefinitely but it exits and total simulation time is 0

 

Can someone tells me why it didn'y gets blocked indefinitely ?

 

#include "systemc.h"

SC_MODULE(event_trial){

    public:

    sc_event p1,p2;

    SC_CTOR(event_trial) {

        SC_THREAD(process1);

        SC_THREAD(process2);

    }

    void process1(){

        while(1){

            wait(p2);

            p1.notify();

        }

    }

    void process2(){

        while(1){

            wait(p1);

            p2.notify();

        }

    }

};

int sc_main(int , char**){

    event_trial et("et");

    sc_start();

    cout<<"Simulation time : "<<sc_time_stamp().value()<<endl;

 }

 

Hello Sir,

First of all, please consult any good reference on SystemC.

Granted that SystemC is basically a ANSI C++ library, there

are some very odd things going on.

1. What exactly is the code trying to achieve ? You mention

'blocks' -- but blocking on what ?

2. How or what is triggering the two events the very first

time ?

3. Invoking 'sc_start' without any arguments would not do

anything useful.

Hope that helps.

Link to comment
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...