亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1487 | 回復(fù): 1
打印 上一主題 下一主題

繼續(xù)請教老師們,關(guān)于線程的問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2009-02-05 22:09 |只看該作者 |倒序?yàn)g覽
重新寫了一個(gè)線程創(chuàng)建函數(shù),但是這次能正常運(yùn)行了。但是我發(fā)的第一個(gè)線程程序錯(cuò)在哪里?還請老師們解答
源程序
#include "stdio.h"
#include "pthread.h"
pthread_once_t once =PTHREAD_ONCE_INIT;
void run(void)
{
printf("Fuction run is running in thread %u\n",pthread_self());
}
int thread1(void)
{
pthread_t thid=pthread_self();
printf("Current thread1's ID is %u\n",thid);
pthread_once(&once,run);
printf("thread1 end\n");
return 0;
}
int thread2(void)
{
pthread_t thid=pthread_self();
printf("Current thread2's ID is %u\n",thid);
pthread_once(&once,run);
printf("thread2 end\n");
return 0;
}
int main()
{
pthread_t thid1,thid2;
pthread_create(&thid1,NULL,(void *(*)(void *))thread1,NULL);
pthread_create(&thid2,NULL,(void *(*)(void *))thread2,NULL);
sleep(3);
printf("main thread exit!,main thread ID is:%u\n",pthread_self());
exit(0);
}
下面是鏈接運(yùn)行結(jié)果
[root@LinuxFzb tmp]# vi thid2.c
[root@LinuxFzb tmp]# gcc -o thid2 thid2.c -lpthread
[root@LinuxFzb tmp]# ./thid2
Current thread1's ID is 1082350784
Fuction run is running in thread 1082350784
thread1 end
Current thread2's ID is 1090739264
thread2 end
main thread exit!,main thread ID is:1073959552
小弟跪謝了,還請指教啊

論壇徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辭舊歲徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
2 [報(bào)告]
發(fā)表于 2009-02-06 02:11 |只看該作者

回復(fù) #1 nervfzb 的帖子

那個(gè)帖子中pthread_create的參數(shù)不對。
if(pthread_create(&thid,NULL,(void*(*)(void *))thread(),NULL)!=0)
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP