Synchronisation help

Steven Schveighoffer schveiguy at gmail.com
Tue Jan 2 03:34:55 UTC 2024


On Monday, 1 January 2024 at 15:48:16 UTC, Anonymouse wrote:
> 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)`?

Yeah, and the thing should be a `Mutex` object. A `Mutex` object 
uses it's underlying mutex primitive as its monitor. This also 
gives options for usage with methods as well as `synchronized` 
statements.

Just make sure you mark it `__gshared` or `shared` so all threads 
see it.

-Steve


More information about the Digitalmars-d-learn mailing list