I am using systemc to model a packet-based network. There are two parallel threads, which process random size packet. After each packet, I'd like to check whether the other thread happens to be in the same status (packet boundary) to avoid conflict.
Any idea how to detect such event concurrency?
To answer the question directly about a method to detect events that happen at the same simulation time:
sc_time_stamp()will return the current simulation time.If your threads record the "last packet time" when constructing a packet, then the thread that executes second can compare its simulation time to the time of the "last packet". A match indicates the concurrent case, and the second executing thread can wait to send its packet.
I'm not sure what kind of system you are developing and if by 'event' you refer specifically to
sc_event, but what I think you really want is arbitration based on availability of a packet. You could have a separate arbitration thread that checks 2 FIFOs for availability of a packet and selects one to process:The exact coding style needed will depend on your usage case for SystemC (TLM LT/AT model vs. synthesis-compatible).