Hardware interview practice
Race a transaction against a scoped watchdog
Run a transaction and a timeout concurrently. Continue when either finishes, stop only the losing child, return one success-or-timeout result, and leave unrelated background processes alive.
Starting point
Question code
task do_transaction();
task wait_timeout();Reviewed example
Work through one case
Input
transaction completes after 8 cycles; timeout would complete after 20 cyclesExpected output
success = 1, the timeout child is stopped, and an unrelated monitor remains aliveThe transaction branch deposits the first result token; join_any returns, and disabling only the named contenders fork removes its losing sibling.
What to cover
Requirements
- Use join_any to detect the first completed contender.
- Cancel the remaining contender before returning.
- Scope disable so it cannot terminate unrelated descendants owned by the caller.
- Publish exactly one success or timeout result, including when completions occur in the same time slot.
