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

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

Chinaunix

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

pthread_self和gettid [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2007-07-16 13:46 |只看該作者 |倒序瀏覽
請問這兩個函數(shù)或系統(tǒng)調(diào)用是不是一回事?我這里它們的返回值是不等的。
比如下面這個程序:

  1. #define _GNU_SOURCE

  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <pthread.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8. #include <sys/syscall.h>


  9. void *thsf(void *arg){
  10.         pthread_t th;
  11.         char *retstr;
  12.         retstr=malloc(50);
  13.         memset(retstr,0,50);
  14.         strcpy(retstr,"New thread quit!");
  15.         th=pthread_self();
  16.         printf("New thread,pid:%d,tid:%x,another tid:%x.\n",getpid(),th,(long)syscall(SYS_gettid));
  17.         pthread_exit(retstr);
  18. }


  19. int main(){
  20.         pthread_t nth1,mth,oth;
  21.         void *a;
  22.         if(pthread_create(&nth1,NULL,thsf,NULL))
  23.                 printf("Error create new thread.\n");
  24.         mth=pthread_self();
  25.         printf("Main thread,pid:%d,tid:%x,another tid:%x.\n",getpid(),mth,(long)syscall(SYS_gettid));
  26.         if(!pthread_join(nth1,&a)){
  27.                 printf("New thread quit,message from new thread:%s.\n",(char *)a);
  28.                 free((char *)a);
  29.         }
  30.         return 0;

  31. }
復(fù)制代碼

論壇徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-08-03 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-08-04 06:20:00
2 [報告]
發(fā)表于 2007-07-16 13:49 |只看該作者
兩種東西

論壇徽章:
0
3 [報告]
發(fā)表于 2007-07-16 13:52 |只看該作者
糊涂了,在主線程中g(shù)ettid跟getpid返回值一致,在新建線程中g(shù)ettid=getpid+1。

如果使用linuxthreads線程庫,它們應(yīng)該是一致的吧?

[ 本帖最后由 hohoxu_hao115 于 2007-7-16 13:57 編輯 ]
您需要登錄后才可以回帖 登錄 | 注冊

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP