I coded part 1 with half an eye on the send/receive interpretation, creating a list of sent values and popping one off for the rcv part. So, once I'd written up the functions, it took very little time to adapt the code to part two.
I was also able to re-use functions from the day 8 vm which I wrote to allow registers or values in all of the appropriate areas.
I did, however, spend most of the day chasing two annoying bugs:
- I was popping the rcv value off the wrong end of the stack.
- A race condition in my threaded version of the solution
Once I fixed the first one, part 2 worked, running the two programs in a scheduler loop, switching between them whenever one was blocked.
I haven't yet solved the threaded version's race condition though. I'm finding it difficult to reliably tell from one thread whether the other thread is also blocked :/