crossbeam icon indicating copy to clipboard operation
crossbeam copied to clipboard

Understanding the safety of channels in the event of a `fork`

Open morrisonlevi opened this issue 3 years ago • 0 comments

I have some multi-threaded code which uses channels to send data back and forth. It's also possible that the program this runs in does a fork.

  1. I need to understand under what conditions locks may be held when sending or receiving data on the channels. I poked around and I didn't see any locks going on, but maybe I just didn't find them. Are there any locks I should be aware of?
  2. After the main thread forks, the child process will have a sender and a receiver appear based on memory state that they have a corresponding receiver and sender but they don't actually exist as the threads don't get created during the fork. I'm not sure if it would be safe to call the destructors of the child's sender and receiver in such situations. I can forget these objects and leak them, but if there's something better to be done, I'd rather do that, you know?

morrisonlevi avatar Sep 15 '22 23:09 morrisonlevi