00001 #include <systemc.h>
00002 #include "during.h"
00003
00004 using namespace std;
00005
00006 struct threads_sol : sc_core::sc_module, sc_during
00007 {
00008
00009 int x;
00010 int id;
00011 void proc_A();
00012
00013 SC_HAS_PROCESS(threads_sol);
00014 threads_sol(sc_module_name name, int _id)
00015 : sc_module(name), id(_id) {
00016 SC_THREAD(proc_A);
00017 }
00018
00019 static void *fct_A(void *arg);
00020 };
00021
00022
00023 void threads_sol::proc_A()
00024 {
00025 for (int i = 0; i < 10; i++) {
00026 x = id;
00027 during(10.0, SC_NS, boost::bind(&threads_sol::fct_A, this));
00028 assert(x == 2 * id);
00029 }
00030 }
00031
00032
00033 void *threads_sol::fct_A(void *arg)
00034 {
00035 threads_sol * self = dynamic_cast<threads_sol *>
00036 (reinterpret_cast<sc_core::sc_module*>(arg));
00037 assert(self->x == self->id);
00038 self->x = 2 * self->id;
00039 return NULL;
00040 }
00041
00042 int sc_main(int argc, char *argv[])
00043 {
00044 (void)argc; (void)argv;
00045
00046 vector<threads_sol *> vect(150);
00047 char s[500];
00048 for(unsigned int i = 0; i < vect.size(); i++) {
00049 sprintf(s, "module_%d", i);
00050 vect[i] = new threads_sol(s, i);
00051 }
00052
00053 cout << "Starting simulation ..." << endl;
00054
00055 {
00056 measure_time t;
00057 sc_start();
00058 }
00059
00060 return 0;
00061 }