Is it safe to run Revise from multiple threads?

Is it safe to run Revise from multiple threads? It seems that Revise in typical usage, e.g. a REPL session, will only run in the interactive thread, and then the updated code will end up run in existing threads, assuming invokelatest is used.

Looking around the Revise codebase, I’m not seeing many locks.

What can happen if a Revise is started in multiple workers threads:

  • Can the compiler perform unsafe overlapping/non-atomic accesses/writes (I guess/hope not)
  • Can Revise do the same to its own internal tracking structures? (it appears so to me)
  • What about the thundering heard effect? If I run Revise in multiple worker threads will they end up duplicating work? (seems to almost definitely be the case)
2 Likes

I got a second opinion on Slack that confirmed my suspicions that the internal tracking structures could have corrupted reads in this case. I’ve filed an issue on Revise.jl here Revise.revise(...) is not safe to be called from multiple threads simultaneously · Issue #845 · timholy/Revise.jl · GitHub, but in the meantime a fairly easy workaround is to put your own locks around the whole of Revise.revise(...).

1 Like

This doesn’t directly address your question, but I believe it is safe to call revise once (from any thread) even while other threads are running in the background. The other threads won’t pick up any changes unless they use invokelatest or invoke in the new world number.

That’s somewhat orthogonal from actually revising code using multiple threads though.

1 Like