# Program Structure when muliple routines need to access State

**URL:** <https://discourse.julialang.org/t/program-structure-when-muliple-routines-need-to-access-state/42918>\
**Category:** Performance\
**Tags:** question, performance, multithreading\
**Created:** [July 12, 2020, 3:04am UTC](https://discourse.julialang.org/t/program-structure-when-muliple-routines-need-to-access-state/42918 "2020-07-12T03:04:16Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![pyrex41](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@pyrex41](https://discourse.julialang.org/u/pyrex41)\
**Post date:** [July 13, 2020, 1:24pm UTC](https://discourse.julialang.org/t/program-structure-when-muliple-routines-need-to-access-state/42918/3 "2020-07-13T13:24:01Z")

</div>

Thank you. The `@lock` macro helps solve a very specific problem, and I was not at all aware of it.

As I dug into the this issue, I discovered I did not really understand how the `$` interpolation for `Threads.@spawn` works for structures (more discussion [here](https://discourse.julialang.org/t/interpolation-into-threads-spawn-macro-fails-for-certain-kinds-of-structs/42964/4)). At any rate, now I’m trying to find a way to measure the impact of using lots of copy operations when all I want to do is read state for a very brief amount of time (but ensure that, for a few milliseconds, I see the full state exactly as it was when my calculation started, no updates). But during this, I may be spawning another process that _does_ need the most up-to-date state…so I cannot lock updates to state during my calculation…

Looks like I need each spawned process to have it’s own copy. But given that only a few changes will happen during the spawned process, still seems like a waste to copy everything.

---

_[View the full topic](https://discourse.julialang.org/t/program-structure-when-muliple-routines-need-to-access-state/42918)._
