On Sunday, 12 April 2015 at 10:04:53 UTC, Marc Schütz wrote:
On Saturday, 11 April 2015 at 19:24:22 UTC, Laeeth Isharc wrote:
Hi.
Two questions:
1. On startup I load various indexes from file storage into
memory in the shared static this segment, and I would like to
access these from threads serving web requests. The data can
be considered immutable once loaded.
What is the best way to make this data accessible? Obviously
static doesn't work as the threads have their own storage (I
think this is what is happening). __gshared works, but is
there a better approach?
You can declare the cache as `immutable` (which is shared
across threads) and assign to it using `assumeUnique()`. You
just need to make sure the initialization really happens only
once, i.e. do it in `main()` or in `shared static this()` as
opposed to `static this()`.
Thanks.
Laeeth