Synchronisation help
user1234
user1234 at 12.de
Tue Jan 2 11:05:33 UTC 2024
On Monday, 1 January 2024 at 15:48:16 UTC, Anonymouse wrote:
> I have a `shared string[int]` AA that I access from two
> different threads. The function I spawn to start the second
> thread takes the AA as an argument.
>
> [...]
>
> What is the common solution here? Do I add a module-level
> `Object thing` and move everything accessing the AA into
> `synchronized(.thing)` statements? Or maybe add a `shared
> static` something to `Foo` and synchronise with
> `synchronize(Foo.thing)`?
Do not use `shared` AA. Use `__gshared` + sync primitives.
`shared` AA will lead to all sort of bugs:
- https://issues.dlang.org/show_bug.cgi?id=20484#c1
- https://issues.dlang.org/show_bug.cgi?id=17088
- https://issues.dlang.org/show_bug.cgi?id=16597
- etc.
More information about the Digitalmars-d-learn
mailing list