SC_THREAD
or SC_CTHREAD
should have infinite loop to keep the thread not being terminated. If you don't put for(;;)
or while(true)
in the function body, when the execution reaches the end of function scope, the thread is terminated. In such case, your thread will never be waken up by the sensitive list for processing something. Or you can it transform to equivalent SC_METHOD
, then you can have no infinite loop.
SystemC is using non-preemptive thread, so if you don't use wait()
to wait for something listed in static or dynamic sensitive list to happen, it causes a infinite execution in your thread. And CPU execution of your process won't get out of the function scope. Such that SystemC kernel won't able to continue to process other methods/threads and events to continue the simulation. And in the event-based simulation, the thread should only be run when the specified condition (events in the sensitive list) occur. So the wait()
function can wait until the next event occurs and hand over the CPU execution to other threads/methods and SystemC kernel. Next time the event occurs, for example the positive edge of clock, wait()
statement will return and continue your process.
In your example, your program is waiting for clock's positive edge trigger to increase the counter's value by 1. So, if you don't put wait()
in your code, then incr_count
will always increase the counter's value infinitely no matter the clock's status, and it won't stop. By using wait()
, your thread will be blocked and wait for next clock positive edge trigger.