Use fork and join for concurrent test threads
mainChiselTest provides a concurrency abstraction for writing testbenches using fork and join. This allows you to spawn threads that run within the simulation cycle without real parallelism.
fork: Spawns a thread. Child threads run immediately, then return to the parent. On subsequent cycles, child threads run before their parent in the order they were spawned.join: Blocks (waits) on a thread.- Safety: The infrastructure checks for collisions or unexpected behavior when pokes/peeks/expects are performed on wires from different threads.
- Synchronization: You can use
fork.withRegion(...)to associate a region with a thread, acting as a synchronization barrier within simulator time steps (useful for monitors).