![](/img/trans.png)
[英]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.