If I have two threads in SystemC, A and B (both SC_THREAD), and I want thread A to stop executing (be reset) if a variable or event in B gets asserted, what is the proper way to accomplish this.
Here is a more illustrative example:
// Thread A: Data transfer
SC_THREAD(rx_tx_transfer);
dont_initialize();
sensitive << clk.pos();
// Thread B: If the value of the control registers changes
// during a transfer, the transfer should be aborted
SC_THREAD(check_reg_write_during_tx);
sensitive << x_event << y_event;
So, I want Thread A to stop what it is doing as soon as I fire an event or signal in Thread B. Maybe this could be accomplished if in A I put in every wait the event in question and the regular clk.pos(), and then do an if-else like this:
void rx_tx_transfer()
{
// code
wait(clk.pos() | event_from_b);
if (clk.read() == SC_LOGIC_1 & event_from_b_var)
{
//...
}
else if (clk.read() == SC_LOGIC_1)
{
//...
}
else
{
//...
}
// other code
wait(clk.pos() | event_from_b);
// repeated if-else code from above
}
I don't like this solution, and hope there is a better way I am unfamiliar with. Perhaps I should have used the async_reset_signal_is() in the SC_THREAD, like so:
// Thread A: Data transfer
SC_THREAD(rx_tx_transfer);
dont_initialize();
sensitive << clk.pos();
async_reset_signal_is(sig_form_b, true);
Would this stop thread A execution and go to reset state when sig_form_b is asseted, no matter the current state of execution of rx_tx_transfer function (i.e, it has not reached the next wait())?
If there is a better or more proper way to do this, please share.