Last active
December 24, 2015 02:09
-
-
Save moretea/6728281 to your computer and use it in GitHub Desktop.
We would expect both programs to print something like
``` <x> execute <x> snoop <x+1> execute <x+1> snoop ....
``` However, this is not the case when using multiple threads within one ``SC_MODULE``` (see output of doesnotwork.cpp)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "aca2013.h" | |
| #include <systemc.h> | |
| #include <iostream> | |
| using namespace std; | |
| SC_MODULE(Thing) { | |
| public: | |
| sc_in<bool> clk; | |
| SC_CTOR(Thing) { | |
| SC_THREAD(execute); | |
| SC_THREAD(snoop); | |
| sensitive << clk.pos(); | |
| dont_initialize(); | |
| } | |
| void execute() { | |
| while(true) { | |
| wait(1); | |
| cout << sc_time_stamp() << " execute" << endl; | |
| } | |
| } | |
| void snoop() { | |
| while(true) { | |
| wait(1); | |
| cout << sc_time_stamp() << " snoop" << endl; | |
| } | |
| } | |
| }; | |
| int sc_main(int argc, char* argv[]) { | |
| sc_clock clk; | |
| Thing thing("meh"); | |
| thing.clk(clk); | |
| sc_start(); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "aca2013.h" | |
| #include <systemc.h> | |
| #include <iostream> | |
| using namespace std; | |
| SC_MODULE(Thing) { | |
| public: | |
| sc_in<bool> clk; | |
| SC_CTOR(Thing) { | |
| SC_THREAD(execute); | |
| sensitive << clk.pos(); | |
| SC_THREAD(snoop); | |
| sensitive << clk.pos(); | |
| dont_initialize(); | |
| } | |
| void execute() { | |
| while(true) { | |
| wait(1); | |
| cout << sc_time_stamp() << " execute" << endl; | |
| } | |
| } | |
| void snoop() { | |
| while(true) { | |
| wait(1); | |
| cout << sc_time_stamp() << " snoop" << endl; | |
| } | |
| } | |
| }; | |
| int sc_main(int argc, char* argv[]) { | |
| sc_clock clk; | |
| Thing thing("meh"); | |
| thing.clk(clk); | |
| sc_start(); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "aca2013.h" | |
| #include <systemc.h> | |
| #include <iostream> | |
| using namespace std; | |
| SC_MODULE(Thing) { | |
| SC_MODULE(Snooper) { | |
| sc_in<bool> clk; | |
| SC_CTOR(Snooper) { | |
| SC_THREAD(snoop); | |
| sensitive << clk.pos(); | |
| } | |
| void snoop() { | |
| while(true) { | |
| wait(1); | |
| cout << sc_time_stamp() << " snoop" << endl; | |
| } | |
| } | |
| }; | |
| public: | |
| sc_in<bool> clk; | |
| Snooper *snooper; | |
| SC_CTOR(Thing) { | |
| SC_THREAD(execute); | |
| sensitive << clk.pos(); | |
| this->snooper = new Snooper("hehe"); | |
| dont_initialize(); | |
| } | |
| void execute() { | |
| while(true) { | |
| wait(1); | |
| cout << sc_time_stamp() << " execute" << endl; | |
| } | |
| } | |
| }; | |
| int sc_main(int argc, char* argv[]) { | |
| sc_clock clk; | |
| Thing thing("meh"); | |
| thing.clk(clk); | |
| thing.snooper->clk(clk); | |
| sc_start(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment