HOME       UP       PREV       NEXT (Blocking and Eventing)  

Example using an SC_THREAD

The earlier `mycounter' example used an SC_METHOD.

Now an example using an SC_THREAD: a data source that provides numbers using a net-level four-phase handshake:

SC_MODULE(mydata_generator)
{ sc_out < int  > data;
  sc_out < bool > req;
  sc_in  < bool > ack;

  void myloop()
  { while(1)
    { data = data.read() + 1;
      wait(10, SC_NS);
      req = 1;
      do { wait(10, SC_NS); } while(!ack.read());
      req = 0;
      do { wait(10, SC_NS); } while(ack.read());
    }
  }

  SC_CTOR(mydata_generator)
  {
    SC_THREAD(myloop);
  }
}

25: (C) 2012-14, DJ Greaves, University of Cambridge, Computer Laboratory.   TAPE MISSING ICON