开发者

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 repli开发者_Python百科ca 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);


Guess What? Solaris already has such a function by the name of forkall! Would love to see a port of it in Linux!


I guess you are talking about continuations. I saw some hits on google (I asked for "continuation c"), but I can't recomend any link, since I don't know your specific needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜