I’m writing a simulator of a distributed system, with the simulation of each server running in its own thread. I’d like to query some elements in the server struct from the thread that spawns the servers. Since the server is mutable, that’s a read/write race. I don’t mind, since the query is only for debugging, and I know how to deal with any inconsistent state.
I tried wrapping the elements I want to look at in Arc::Mutex<_>, but that complicated the server code. Instead, I now have a wrapped copy for each variable that I query. (It’s not as bad as it sounds, since all relevant updates are in a single function.) Is there a better way to do this? I don’t mind using unsafe.