【发布时间】:2012-05-30 17:52:45
【问题描述】:
完成后如何关闭线程?比如确保没有任何东西是打开的或运行的?
到目前为止,我知道如何打开它,但是.. 不知道如何正确关闭它
int iret1;
pthread_t thread1;
char *message1;
void *multithreading1( void *ptr ) {
while (1) {
// Our function here
}
}
int main (int argc, char * const argv[]) {
if( (iret1=pthread_create( &thread1, NULL, multithreading1, (void*) message1)) )
{
printf("Thread creation failed: %d\n", iret1);
}
return 0;
}
【问题讨论】:
-
顺便说一句,在您的示例中,当 main() 到达
return 0时,您的整个程序将退出(包括您的 pthread)。 -
没错,只是确保我使用的电量更少
标签: c++ c multithreading pthreads