[英]How to exit a blocking call of recv() on a thread from a different thread?
[英]How to exit from function that calls thread but keep thread going?
我一直在从事一些C项目,其中有一个调用pthread_create()
的函数,但我需要该函数返回并保持线程化函数继续运行。
这是我的代码:
audio_file
play(char file_name[])
{
/* Plays audio file */
pthread_t thread;
audio_file a_file = p_get_file(file_name);
if(a_file.type != BROKEN)
pthread_create(&thread,NULL,audio_output,&a_file);
return a_file;
}
您在应该继续运行的线程中执行pthread_detach。 如果该线程是从主线程创建的,则主线程应使用pthread_exit而不是exit()退出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.