我在 Visual Studio 2008(64 位)中通过在开头设置断点调试了以下代码do_test1
,do_test2
令我惊讶的是,代码在函数的同一线程中sc_main
运行。
我没有在Linux环境中调试。但是,通过搜索源代码,我发现它"pthread.h"
被包含在一些 SystemC 库源代码中。
问题1:在Windows中,会SC_THREAD
创建一个真正的线程吗?或者它总是在同一个线程中sc_main
?如果是这种情况,我可以说SC_THREAD
是创建一个“假”线程吗?
问题2:在Linux中,既然"pthread.h"
被包含,会不会SC_THREAD
创建一个新线程?
问题 3:在 Windows 和 Linux 中,我是否遗漏了一些设置来启用真正的线程?
=========================================
以下代码来自该网站:
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
}