CreateThread vs fork() [英] CreateThread vs fork()

查看:121
本文介绍了CreateThread vs fork()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

fork()和CreateThread之间是否存在某种关系?有什么事吗 CreateThread在内部调用fork()?

Do we have any sort of relationship between fork() and CreateThread? Is there anything that CreateThread internally calls fork()?

推荐答案

在NT中,基本工作单元称为线程(即NT调度线程,而不是进程).用户线程在进程的上下文中运行.调用CreateThread时,您要求NT内核在您的进程上下文中分配一个工作单元(您也可以使用基本上是线程的纤维来安排自己的时间,但这超出了您的问题).

In NT, the fundamental working unit is called a thread (ie NT schedules threads, not processes.). User threads run in the context of a process. When you call CreateThread, you request the NT kernel to allocate a working unit within the context of your process (you also have fibres that are basically threads you can schedule yourself but that's beyond the topic of your question).

当您调用CreateThread时,将为该函数提供一个入口点,该入口点将在调用该函数后运行.代码必须在流程的虚拟空间内,并且页面必须具有执行权限.简而言之,您可以提供一个函数指针. ;)

When you call CreateThread you provide the function with an entry point that is going to be run after the function is called. The code must be within the virtual space of the process and the page must have execution rights. Put simply, you give a function pointer. ;)

fork()是UNIX函数,它请求内核创建正在运行的进程的副本.父进程获取子进程的pid,子进程获取0(这样您就知道自己是谁).

fork() is an UNIX function that requests the kernel to create copy of the running process. The parent process gets the pid of the child process and the child process gets 0 (this way you know who you are).

如果希望在Windows中创建进程,请调用CreateProcess函数,但是它的行为不像fork().原因是大多数时候您将创建线程而不是进程.

If you wish to create a process in Windows, you call the CreateProcess function, but that doesn't behave like fork(). The reason being that most of the time you will create threads, not processes.

如您所见,CreateThread和fork之间没有关系.

As you can see, there is no relation between CreateThread and fork.

这篇关于CreateThread vs fork()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆