Jump to content

sc_process suspend/resume and disable/enable confusion


mohitnegi

Recommended Posts

for suspend/resume

#include "systemc.h"

class test : public sc_module {
	public :
	sc_process_handle t ;
	SC_HAS_PROCESS(test);
	test(sc_module_name){
		SC_THREAD(run);
		t = sc_get_current_process_handle();
		SC_THREAD(run2);
	} 
	void run(){
		wait(10,SC_NS);
		cout<<"T :run1 "<<sc_time_stamp().value()<<endl;
		wait(5,SC_NS);
		cout<<"T :run2 "<<sc_time_stamp().value()<<endl;
	}

	void run2(){
	    wait(10,SC_NS);
		cout<<"T :run3 "<<sc_time_stamp().value()<<endl;
	    t.suspend();
	    //t.disable();
		cout<<"T :run4 "<<sc_time_stamp().value()<<endl;
	    wait(20,SC_NS);
		cout<<"T :run5 "<<sc_time_stamp().value()<<endl;
	    t.resume();	
	    //t.enable();	
		cout<<"T :run6 "<<sc_time_stamp().value()<<endl;
	//t.reset();
	}
	
};

int sc_main(int, char**){
	test t("test");
	sc_start();
	return 0;
}
mic-24@localhost tmp]$ ./run.x 

        SystemC 2.3.1-Accellera --- May  1 2014 15:38:34
        Copyright (c) 1996-2014 by all Contributors,
        ALL RIGHTS RESERVED
T :run1 10000
T :run3 10000
T :run4 10000
T :run5 30000
T :run6 30000
T :run2 30000

here i dont understand why final value is 30000 not 35000 and what happenened to this "wait(5,SC_NS);"

 

 

now in disable/resume

#include "systemc.h"

class test : public sc_module {
	public :
	sc_process_handle t ;
	SC_HAS_PROCESS(test);
	test(sc_module_name){
		SC_THREAD(run);
		t = sc_get_current_process_handle();
		SC_THREAD(run2);
	} 
	void run(){
		wait(10,SC_NS);
		cout<<"T :run1 "<<sc_time_stamp().value()<<endl;
		wait(5,SC_NS);
		cout<<"T :run2 "<<sc_time_stamp().value()<<endl;
	}

	void run2(){
	    wait(10,SC_NS);
		cout<<"T :run3 "<<sc_time_stamp().value()<<endl;
	    //t.suspend();
	    t.disable();
		cout<<"T :run4 "<<sc_time_stamp().value()<<endl;
	    wait(20,SC_NS);
		cout<<"T :run5 "<<sc_time_stamp().value()<<endl;
	    //t.resume();	
	    t.enable();	
		cout<<"T :run6 "<<sc_time_stamp().value()<<endl;
	//t.reset();
	}
	
};

int sc_main(int, char**){
	test t("test");
	sc_start();
	return 0;
}
[mic-24@localhost tmp]$ ./run.x 

        SystemC 2.3.1-Accellera --- May  1 2014 15:38:34
        Copyright (c) 1996-2014 by all Contributors,
        ALL RIGHTS RESERVED
T :run1 10000
T :run3 10000

Error: (E559) Undefined process control interaction: attempt to disable a thread with timeout wait: test.run
In file: ../../../../src/sysc/kernel/sc_process.cpp:345
In process: test.run2 @ 10 ns
[mic-24@localhost tmp]$ 

what is the problem here ???

Link to comment
Share on other sites

First, why are you calling the .value() method? To output time, you should use just sc_time_stamp() or possibly (but not necessary) .to_string() method.

 

  cout << sc_time_stamp() << endl;

 

Next, you have a race condition. Process run() and run2() are not guaranteed to start in any particular order with respect to each other. Yes, for a given simulator implementation, one will run before the other, but that is purely based on the implementation. The standard is very specific about this aspect.

 

Next, the error in your disable/enable situation occurs because run2() is attempting to control run(), but run() has already terminated.

 

See http://videos.accellera.org/ieee16662011/index.html for more information.

Link to comment
Share on other sites

First, why are you calling the .value() method? To output time, you should use just sc_time_stamp() or possibly (but not necessary) .to_string() method.

 

  cout << sc_time_stamp() << endl;

 

Next, you have a race condition. Process run() and run2() are not guaranteed to start in any particular order with respect to each other. Yes, for a given simulator implementation, one will run before the other, but that is purely based on the implementation. The standard is very specific about this aspect.

 

Next, the error in your disable/enable situation occurs because run2() is attempting to control run(), but run() has already terminated.

 

See http://videos.accellera.org/ieee16662011/index.html for more information.

 

In perfect agreement with your comments, it appears that using some of the built-in

SystemC synchronization primitives would provide the necessary control. Tricky no

doubt.

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