Jump to content

milesma

Members
  • Content Count

    4
  • Joined

  • Last visited

  1. I've fixed the issue. In short, it is my code's problem (the delete is not at the correct place; besides, there are memory leaks) Be very careful when using pointer type as signal/port. when sc_start evaluating whether there are activities pending, it is actually comparing m_cur_val and m_new_val. In my case, the first time assigning eventSubject = new Event(...), say the address is 0x1234 then it is released by "delete event;" Now: m_cur_val is pointing to "0x1234" with value 0xfeeefeee (because it is released) Now comes to "eventSubject = new Event(...)", the memory is allocated at "0x1234" as well. so m_new_val is "0x1234". since m_cur_val == m_new_val, SystemC thought there is no activity pending, so the SC_MODULE won't be invoked. How to fix: add following two lines of code: eventSubject = NULL; sc_start();
  2. After Signal/Port binding, when signal changed, the sensitive list will cause SC_METHOD registered method to run. When I'm implementing the SystemC version, I met this warning W571. To be honest, I think this warning is correct because there is no activity. But Why there is no activity where I thought there should be is the question. The problem happens when call sc_start() the second time; I suspect that the binding between signal/port is not handing well. SC_MODULE ( MyClass ) { SC_CTOR(MyClass) { SC_METHOD(eventListener); dont_initialize(); sensitive << m_event; } void eventListener() { Event* event = m_event.read(); ... delete event; } } int sc_main (int argc, char* argv[]) { sc_signal<Event*> eventSubject; MyClass context("CONTEXT"); context.m_event(eventSubject); //bind signal to port, m_event is the port while(true) { getline(cin, in); ... eventSubject = new Event(); sc_start(); } }
  3. milesma

    Will SC_THREAD create a real thread?

    Thanks Philipp, I never know the concept of "co-routine" before, now I know it is an alternative of thread during concurrent programmig.
  4. Hi Guys, It is my first day to read SystemC tutorial, forgive me if the questions are silly. 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 }
×