Example - cont...
n//
the producer module
nclass
producer : public sc_module
n{
npublic:
nsc_port<write_if>
out; // producer output port
nSC_CTOR(producer)
// module constructor
n{
nSC_THREAD(main);
// start the process
n}
nvoid
main() // the producer process
n{
nchar
c;
nwhile
(true) {
n...
nout->write(c);
// write c into fifo
nif
(...)
nout->reset();
// reset the fifo
n}
n}
n};
n//
the consumer module
nclass
consumer : public sc_module
n{
npublic:
nsc_port<read_if>
in; // consumer input port
nSC_CTOR(consumer)
// module constructor
n{
nSC_THREAD(main);
// start the process
n}
nvoid
main() // the consumer process
n{
nchar
c;
nwhile
(true) {
nin->read(c);
// read c from the fifo
nif
(in->num_available() > 5)
n...;
// perhaps speed up processing
n}
n}
n};