Linux signal handling - notifying a condition variable
Jim King
jking at apache.org
Thu Mar 15 17:30:50 UTC 2018
On Thursday, 15 March 2018 at 17:12:24 UTC, Adam D. Ruppe wrote:
> On Thursday, 15 March 2018 at 16:51:59 UTC, Jim King wrote:
>> In going through the signal documentation it looks like the
>> signal handler must be a "nothrow @nogc" variety.
>
> Looks like notify actually can throw an exception... the way I
> usually do signal handlers is just set a global variable:
>
> __global bool interrupted = false;
> void sigint_handler() { interrupted = true; }
>
> then in the main loop check that periodically... idk if that'd
> work well withthe condition variable though, I have never
> actually used that...
Thanks for that suggestion; I was in the middle of implementing
that. The problem with that is that it requires a busy loop to
detect it. It is far better to block on condition variables than
to have a busy loop.
I agree condition variable notify could throw if the condition
variable is not in the correct state. I think it would be
possible for someone to catch this and make sure it does not
throw, but the "@nogc" part of it seems a bit more involved.
Condition variables (and mutexes) are supposed to be usable from
a signal handler.
More information about the Digitalmars-d
mailing list