# Is it safe to run Revise from multiple threads?

**URL:** https://discourse.julialang.org/t/is-it-safe-to-run-revise-from-multiple-threads/119743
**Category:** General Usage
**Tags:** multithreading, revise
**Created:** [September 23, 2024, 12:30pm UTC](https://discourse.julialang.org/t/is-it-safe-to-run-revise-from-multiple-threads/119743 "2024-09-23T12:30:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![frankier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankier/32/35101_2.png) [@frankier](https://discourse.julialang.org/u/frankier)
#### Post date: [September 23, 2024, 12:30pm UTC](https://discourse.julialang.org/t/is-it-safe-to-run-revise-from-multiple-threads/119743/1 "2024-09-23T12:30:20Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![frankier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankier/32/35101_2.png) [@frankier](https://discourse.julialang.org/u/frankier)
#### Post date: [September 23, 2024, 5:20pm UTC](https://discourse.julialang.org/t/is-it-safe-to-run-revise-from-multiple-threads/119743/2 "2024-09-23T17:20:48Z")

</div>

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](https://github.com/timholy/Revise.jl/issues/845), but in the meantime a fairly easy workaround is to put your own locks around the whole of `Revise.revise(...)`.

---

<div class="post-metadata">

### Author: ![sefffal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sefffal/32/23640_2.png) [@sefffal](https://discourse.julialang.org/u/sefffal)
#### Post date: [September 23, 2024, 5:26pm UTC](https://discourse.julialang.org/t/is-it-safe-to-run-revise-from-multiple-threads/119743/3 "2024-09-23T17:26:45Z")

</div>

> [@frankier](#):
>
> [Revise.revise(…) is not safe to be called from multiple threads simultaneously · Issue #845 · timholy/Revise.jl · GitHub](https://github.com/timholy/Revise.jl/issues/845)

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.
