Is it possible to initialize a static once, then share it between threads without a mutex?

53 points FurCollarCriminal

I'm writing a program that takes a config parameter on startup which is used extensively throughout the program, and from many threads.

What I want to do is load the config at the start of the program (before any other threads have been spawned), save the parameter into a static, then reference the static throughout execution. It is inconvenient to thread the parameter throughout my program, as it would have to appear in hundreds of function signatures.

As the parameter is totally immutable/unchanging, it seems unnecessary to wrap the static in a mutex, e.g. \OnceLock\\. I'm doing a lot of heavy computation across threads and don't want to be locking when reading this parameter.

Is there an abstraction suitable for this use-case?