[英]Using _endthread();
Today I started working on a project where I need use thread's, I'm using functions from process.h: _beginthread and _endthread. 今天,我开始研究需要使用线程的项目,正在使用process.h中的函数:_beginthread和_endthread。
My question is, I really need use _endthread(); 我的问题是,我真的需要使用_endthread();。 at the end of function? 在功能结束时?
void LGThread(void *null_ptr) {
/* ... code ...*/
_endthread();
}
void main() {
_beginthread(LGThread, NULL, NULL);
}
Or even with: 甚至:
void LGThread(void *null_ptr) {
/* ... code ...*/
}
void main() {
_beginthread(LGThread, NULL, NULL);
}
I'm fine? 我很好? What it does specially? 它特别做什么?
You don't need it. 不用了 And in a C++ program it can be harmfull: It does not return, so destructors will not be called for objects allocated on the stack in the thread function. 在C ++程序中,它可能是有害的:它不会返回,因此不会在线程函数中为堆栈上分配的对象调用析构函数。
You are using Windows functions. 您正在使用Windows功能。 In C++, the standard is std::thread
from <thread>
. 在C ++中,标准是<thread>
std::thread
。
That said, you don't need _endthread
just like you don't need exit(0)
. 就是说,您不需要_endthread
就像您不需要exit(0)
。 Just returning is sufficient. 只需返回就足够了。 [edit] Scott has a point, returning is even better as that does run destructors. [编辑]斯科特(Scott)有一点,返回更好,因为它确实运行析构函数。 Ie _endthread
is actually more like abort()
. 即_endthread
实际上更像abort()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.