I know there is no standard way of forking a multithreaded process. However, one thing come into my mind, which is that since the forked process is the exact replica or the original process, the thread stacks would be there.
Does anyone have any idea of how to restart the threads from their last execution state in the forked process. For simplicity, we can assume that there were no acquired locks at the time of forking. Say for example, forking was done between two barriers.
Threads execution state is not only the data in stack. It is also set of CPU registers, which is lost.
do_fork()
system call just don't copy any thread other from thread, which executes a syscall do_fork -> copy_process and there is a single call to copy_thread at line 1181
retval = copy_thread(clone_flags, stack_start, stack_size, p, regs);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With