Skip to content

Instantly share code, notes, and snippets.

@moretea
Last active December 24, 2015 02:09
Show Gist options
  • Select an option

  • Save moretea/6728281 to your computer and use it in GitHub Desktop.

Select an option

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)
#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;
}
#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;
}
#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