I debugged following code in Visual Studio 2008 (64 bit) by setting break point at the start of do_test1
and do_test2
, to my suprise, the code is running in the same thread of the sc_main
function.
I didn't debug in Linux environment. However, by searching the source code, I found the "pthread.h"
was included by some SystemC library source code.
Question 1: In Windows, will the SC_THREAD
create a real thread? Or it is always in the same thread of sc_main
? If this is the case, may I say SC_THREAD
is creating a "fake" thread?
Question 2: In Linux, since "pthread.h"
is included, will SC_THREAD
create a new thread?
Question 3: In Windows and Linux, did I miss some settings to enable the real thread?
========================================
Following code is from this website:
http://www.asic-world.com/systemc/systemc_time4.html#Example_:_sc_event
#include <systemc.h>
SC_MODULE (events) {
sc_in<bool> clock;
sc_event e1;
sc_event e2;
void do_test1() {
while (true) {
// Wait for posedge of clock
wait();
cout << "@" << sc_time_stamp() <<" Starting test"<<endl;
// Wait for posedge of clock
wait();
cout << "@" << sc_time_stamp() <<" Triggering e1"<<endl;
// Trigger event e1
e1.notify(5,SC_NS);
// Wait for posedge of clock
wait();
// Wait for event e2
wait(e2);
cout << "@" << sc_time_stamp() <<" Got Trigger e2"<<endl;
// Wait for posedge of clock
wait();
cout<<"Terminating Simulation"<<endl;
sc_stop(); // sc_stop triggers end of simulation
}
}
void do_test2() {
while (true) {
// Wait for event e2
wait(e1);
cout << "@" << sc_time_stamp() <<" Got Trigger e1"<<endl;
// Wait for 3 posedge of clock
wait(3);
cout << "@" << sc_time_stamp() <<" Triggering e2"<<endl;
// Trigger event e2
e2.notify();
}
}
SC_CTOR(events) {
SC_CTHREAD(do_test1,clock.pos());
SC_CTHREAD(do_test2,clock.pos());
}
};
int sc_main (int argc, char* argv[]) {
sc_clock clock ("my_clock",1,0.5);
events object("events");
object.clock (clock);
sc_start(); // Run the simulation till sc_stop is encountered
return 0;// Terminate simulation
}