# How to make a global constant thread local?

**URL:** <https://discourse.julialang.org/t/how-to-make-a-global-constant-thread-local/37595>\
**Category:** General Usage\
**Created:** [April 14, 2020, 11:06pm UTC](https://discourse.julialang.org/t/how-to-make-a-global-constant-thread-local/37595 "2020-04-14T23:06:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chong\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chong_wang/32/20307_2.png) [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)\
**Post date:** [April 14, 2020, 11:06pm UTC](https://discourse.julialang.org/t/how-to-make-a-global-constant-thread-local/37595/1 "2020-04-14T23:06:45Z")

</div>

To make my code thread-safe, I am making some constant thread local. However, in the following package example

```julia
module Foo

const bar = zeros(Threads.nthreads())

end

```

the length of `bar` will be stuck at `JULIA_NUM_THREADS` at the time of compilation.

What’s the correct way to make the constant `bar` thread local?

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [April 14, 2020, 11:17pm UTC](https://discourse.julialang.org/t/how-to-make-a-global-constant-thread-local/37595/2 "2020-04-14T23:17:40Z")

</div>

You can create an empty array (or array of whatever size) where you define `bar` and then `resize!` it in an ` __init__ ()` method (see here: [Modules · The Julia Language](https://docs.julialang.org/en/v1/manual/modules/index.html#Module-initialization-and-precompilation-1)).
