#Is reading/writing to a process from different threads safe?

1 messages · Page 1 of 1 (latest)

static tree
#

I was wondering if it's safe to have one thread writing to a ChildProcess' stdin and another thread reading its stdout simultaneously?

I'm getting some deadlocks when calling process.kill();, so I wonder if it's safe to do that in the first place or if the bug is somewhere else

summer silo
#

Killing another process should be very rare. If you're killing the process that your write thread is currently blocked on until that process reads (and vice versa), then you need to find a more opportune time to do your killing.

static tree
#

I'm only killing in case of an error. But when that happens there's a deadlock, the .kill() never finishes, not the write/read thread.

fast thorn
#

Reading and writing two separate handles should be fine, yes.
And yeah, I will echo "don't use kill" - you really want to have some sort of condition that the thread checks often and simply use that to have it terminate normally.