oconnor663 / shared_child.rs

a wrapper around std::process::Child that lets multiple threads wait or kill at once
MIT License
39 stars 7 forks source link

Comparison with ClonableChild crate #9

Closed faern closed 7 years ago

faern commented 7 years ago

Hi,

Just saw this crate, and notice that it is virtually doing the same as my clonablechild crate. Just wanting to check in if there is any difference that I miss?

Since it's a very isolated and small problem it should more or less only be one correct solution I think. Thus we could maybe combine forces? If your library does stuff better I will remove mine.

I also put the standard Child in a Mutex. But where you seem to use a special procedure to wait I use the built in wait. And where you use the built in kill method I have my own kill implementation for when the Mutex is already taken.

I probably have the reused pid race condition you talk about in your README.

oconnor663 commented 7 years ago

Oh cool! Agreed that they're very similar use cases. Some scattered thoughts along the lines you mentioned:

oconnor663 commented 7 years ago

Actually I'm not sure setting a "this child has already exited flag" will be good enough in your API. I could call new with a child that's already been waited on, and the CloneableChild would then be in the wrong state. Triggering the custom kill path (like by calling kill on two threads at once) would then always try to kill the PID, even if there was normally bookkeeping in place to prevent that.

I just shipped some changes to always use Child::wait and Child::kill under the hood, to avoid a similar issue after the child is returned from my into_inner. (Though I still avoid accepting children from the caller -- instead I spawn them myself.)

faern commented 7 years ago

Thanks for the detailed explanation. At first I thought about patching up clonablechild as well, but I realized that was not the best solution. The best IMO would be to not even have two crates solve the same, very small, problem. So I yanked all versions of clonablechild and added a deprecation notice in the README.

Just out of curiosity, you never saw clonablechild before publishing this, or what made you create a new crate instead of improving the existing one?

oconnor663 commented 7 years ago

Sadly I never saw it. There was some discussion about the problem on the try_wait tracking issue, and I guess I assumed that if anyone on that thread knew about an existing crate they would've mentioned it there.

oconnor663 commented 7 years ago

Will close for now, but let me know if anything changes. I'd be happy to work together to port fixes.