Thread communication
Chris via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 6 03:09:15 PDT 2015
On Thursday, 6 August 2015 at 08:40:58 UTC, Kagamin wrote:
}
>
> AFAIK, boost does it by integrating support for interruption
> into various functions, so IO, waits and locks reply to
> interrupt requests appropriately. You can do something similar.
I understand the philosophy behind D-threads. However, I have a
situation where waiting for a thread to react to an abort signal
(if it reacts at all) and finish according to a protocol can
cause a delay that may not be acceptable to the user or cause
inconsistencies. Instant abortion works best with data sharing.
However, then I have the ugly situation where I have to place the
abort flag at strategical places in several functions/blocks to
make sure the task will not be pursued, because you never know
when exactly the new input will arrive. In this way it can be
intercepted. Unfortunately, this is messy and it is not easy to
avoid data races.
A possible solution would be to halt all threads except for the
main thread, spawn a new thread, and end the old thread silently
behind the scenes. I'm not sure, if this is possible though. I
also wonder, if it would be possible to use some sort of observer
that never sleeps.
More information about the Digitalmars-d-learn
mailing list