On Wednesday, 31 January 2018 at 17:44:37 UTC, Russel Winder wrote:
So, I have an application which has a sort of nano-services architecture, basically it is a set of communicating processes. Terminating those processes blocked on an input channel is quite easy, send a terminate message on the input channel. But what about a process that has no input channel, one that is blocked on OS events?

Is there a way of forcibly, but nicely, terminating a spawned process that never executes `receive()`?

Assuming your're talking about threads: there's no secure method of forcing the thread to stop. Threads share the state (eg. can hold the locks) and killing them is always risky.

If your threads are blocked reading the socket, you probably can close these sockets and exit after the read error.

Another way is to use atomic flag indicating that thread needs to be interrupted. After any blocking operation, the thread have to check this flag and finish the job. It's good to use timeouts (eg socket timeout) in such scenario (if possible).

Arek

Reply via email to