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

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

Chinaunix

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

關(guān)于pthread編譯的一個(gè)奇怪問(wèn)題! [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2006-09-16 11:25 |只看該作者 |倒序?yàn)g覽
我自己寫(xiě)了一個(gè)很簡(jiǎn)單的pthread程序,前面用了#include <pthread.h>
然后用gcc myPthread.c居然能通過(guò)編譯????
但是運(yùn)行時(shí),pthread_creat函數(shù)卻沒(méi)有正確地創(chuàng)建線程。但為什么能通過(guò)編譯呢?

我知道正確的編譯應(yīng)該是:gcc myPthread.c -lpthread

但是,奇怪的是,為什么用gcc myPthread.c也能通過(guò)編譯?
謝謝大俠的回答!

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2006-09-16 12:57 |只看該作者
程序帖出來(lái)

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2006-09-16 14:29 |只看該作者
程序基本就是高程里面的內(nèi)容了,如下:

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <pthread.h>


pthread_t pthid;

void printids(const char *s)
{
  pid_t      pid;
  pthread_t  tid;
  
  pid=getpid();
  tid=pthread_self();
  //tid=pthid;
  printf("%s pid %u tid %u (0x%x)\n", s,pid, tid, tid);
}

void *thr_fn(void *arg)
{
  printids("new  thread: ");
  //return(0);
  pthread_exit((void *)2);
}

int main(void)
{
int err;
void *t_ret;
err=pthread_create(&pthid,NULL,thr_fn,NULL);
if(err!=0) printf("creat thread unsuccessful!\n");
printids("main thread: ");
err=pthread_join(pthid,&t_ret);
if(err!=0) printf("cannot join with phtid!\n");
printf("thread exit code: %d \n",t_ret);
//sleep(1);
exit(0);
}


運(yùn)行環(huán)境:Solaris 9

編譯和運(yùn)行1:
# gcc myPthread.c
# a.out
creat thread unsuccessful!
main thread:  pid 23984 tid 1 (0x1)
thread exit code: 4
#

編譯和運(yùn)行2:
# gcc myPthread.c -lpthread
# a.out
main thread:  pid 23990 tid 1 (0x1)
new  thread:  pid 23990 tid 2 (0x2)
thread exit code: 2
#

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2006-09-16 14:32 |只看該作者
顯然,上述的“編譯和代碼1”是錯(cuò)誤的,但奇怪的是,居然能通過(guò)編譯。
大家討論討論呢。
謝謝!

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2006-09-17 11:06 |只看該作者
我的問(wèn)題沒(méi)人回答??????
求救斑竹了

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2006-09-17 16:12 |只看該作者
很顯然,你的機(jī)器有問(wèn)題.
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(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)專(zhuān)區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP