# How to return from SystemC thread with error code?

I've got a SystemC testbench (for a VHDL DUT but that's irrelevant right now). I'd like to be able to cause the test to terminate, with a specific exit code, from within an SC_CTHREAD. I am pretty new to SystemC (I'm mostly a verilog/sv guy).

I've tried simply including "exit(error_code)" but while that terminates the simulation, the final exit code comes from my sc_main's return statement. Edit: I guess this makes sense since the "exit" probably terminates the separate thread with that exit code, but not the sc_main thread.

I've tried calling sc_stop before that exit, and usually get an error about calling a pure virtual method (I believe that's end_of_simulation, which I have not defined....but that should be optional, right?).

The only way I see to affect the exit code of the process is to change the return statement of sc_main, but that doesn't quite work when all my action is happening in an SC_THREAD created by a constructor of an object somewhere (if it's not obvious I truly don't understand how SystemC works very well, probably because there's a lot of hidden action with secret classes that we can't see, as opposed to verilog where simulation ordering is all there is, assuming you understand blocking/non-blocking).

Note: I am running with a commercial simulation tool, and not pure C++. It's possible that there's an implementation bug there. I'm trying to get our pure C++ compile running but it seems to have broken a while ago (I'm not responsible for the SystemC model).

• I'm also posting this on stackoverflow since there are far more SystemC questions there than here. – Matt Apr 22 '19 at 16:37

return(test_module.exit_code);