在线程中运行函数 [英] Running a function in a thread
本文介绍了在线程中运行函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想执行上述操作。
void myFunc()
{
... // several stuff
}
...
int main()
{
...
// I would like to run myFunc in a thread so that the code below could execute
// while it is being completed.
...
}
你建议我应该怎么办?
What do you suggest I should do? Which function call from which library would enable me to complete my goal?
推荐答案
对于Win32编程,您可以使用 beginthread
。还有 CreateThread
,但如果我记得正确,那不会初始化C / C ++环境,这会导致问题。
For Win32 programming, you can use beginthread
. There is also CreateThread
, but if I remember correctly, that doesn't initialize the C/C++ environment, which leads to problems.
编辑:刚刚选中 - MSDN状态可执行文件中调用C运行时库(CRT)的线程应该使用_beginthread和_endthread函数的线程管理,而不是CreateThread和ExitThread。
Just checked - MSDN states "A thread in an executable that calls the C run-time library (CRT) should use the _beginthread and _endthread functions for thread management rather than CreateThread and ExitThread".
这篇关于在线程中运行函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文