Best practices for multithread global flags
rikki cattermole
rikki at cattermole.co.nz
Wed Nov 15 12:02:33 UTC 2017
On 15/11/2017 11:57 AM, Vladimirs Nordholm wrote:
> Hello people from D-land.
>
> To summarise my problem: I have a program in the terminal (Posix) with
> two threads: one which my main program is run on, and a second one which
> polls input via `poll(...)` and `read(...)`.
>
> Let's call main thread T1, and a semi-blocking input-thread T2.
>
> Every second T2 checks if T1 is terminated by checking if the a global
> flag is set to true. This is done with a `while(global_flag)`.
>
> This feels to me like iffy code. So my question becomes: what is the
> best way to do this check with?
You're fine, a __gshared variable will do this nicely.
More information about the Digitalmars-d-learn
mailing list