Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restarting threads in forked process

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.

like image 776
MetallicPriest Avatar asked Oct 11 '22 14:10

MetallicPriest


1 Answers

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);
like image 170
osgx Avatar answered Oct 14 '22 02:10

osgx