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

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

Chinaunix

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

線程頭文件問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2009-11-18 21:50 |只看該作者 |倒序?yàn)g覽

------------------------------------------------------------
pthrad1.h
------------------------------------------------------------
#
#
#

extern void pthread1(void);



-------------------------------------------
pthread.c
--------------------------------------------

void pthrad1(void)
{
    ....
    ....
}


------------------------------------------
main.c
-------------------------------------------
#include  "pthread1.h"
int main(int argc, char **argv)
{
      .....
       pthread = pthread_create(&id1, NULL, (void *)pthread1,NULL);
}





編譯的時候竟然告訴我     pthraed1沒定義。后來在main中exern pthread1();之后就好了。

經(jīng)常是在main中寫函數(shù)的 實(shí)現(xiàn)。最經(jīng)發(fā)現(xiàn)很多高手都是一個線程用一套.h和.c文件搞定。然后在main函數(shù)中create線程。
但是今天自己寫的時候卻出現(xiàn)問題。不僅是函數(shù)說沒找到。
我在main.c文件中定義的全局變量編譯時在pthread.c中也報(bào)錯說沒定義。

請各位指點(diǎn)。謝謝

[ 本帖最后由 feiyinziiu 于 2009-11-18 21:51 編輯 ]

論壇徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵節(jié)徽章
日期:2015-03-06 15:50:392015亞冠之大阪鋼巴
日期:2015-06-12 16:01:352015年中國系統(tǒng)架構(gòu)師大會
日期:2015-06-29 16:11:2815-16賽季CBA聯(lián)賽之四川
日期:2018-12-17 14:10:21
2 [報(bào)告]
發(fā)表于 2009-11-18 22:50 |只看該作者
編譯的時候是不是加個-lpthread -pthread一類的呢?

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2009-11-18 22:59 |只看該作者

回復(fù) #2 T-Bagwell 的帖子

加了  -lpthread.

斑竹,我想問下。我有3個線程。分別每個線程都有 .h  .c文件組成。
然后再

main.c  #include  "  .h"
然后再在main()函數(shù)之外申請的只要不是static變量,我定義其他的變量,那么在我的那些線程.c文件中使用都沒問題把?

我自己寫的Makefile如下。

EXEC = main
OBJS = main.o water_pthread.o time_pthread.o
SRC = main.c time_pthread.c water_pthread.c

CC = gcc

$(EXEC) : $(OBJS)
         $(CC) -o $(EXEC)  $(OBJS)  -lpthread
main.o:time_pthread.h  water_pthread.h


clean:
         rm -rif *.o


我在main.c 里。main()函數(shù)之外申請的互斥鎖,在其他的幾個線程函數(shù)中,也報(bào)錯說我沒定義。。

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2009-11-18 23:03 |只看該作者
main.c函數(shù)如下:
#include "time_pthread.h"
  2 #include "water_pthread.h"
  3 #include <stdio.h>
  4 #include <stdlib.h>
  5 #include <unistd.h>
  6 #include <sys/types.h>
  7 #include <pthread.h>
  8
  9
10 pthread_cond_t g_collect_info = PTHREAD_COND_INITIALIZER;
11 pthread_mutex_t g_condition_mutex = PTHREAD_MUTEX_INITIALIZER;
12
13 int main(int argc, char **argv)
14 {
15         pthread_t id1, id2, id3;
16         int ret1, ret2, ret3;
17 //      extern void water_pthread(void);
18
19 //      pthread_cond_t g_collect_info = PTHREAD_COND_INITIALIZER;
20 //      pthread_mutex_t g_condition_mutex = PTHREAD_MUTEX_INITIALIZER;         
21
22         ret1 = pthread_create(&id1, NULL, (void *)time_pthread, NULL);
23         ret2 = pthread_create(&id2, NULL, (void *)water_pthread, NULL);
24
25         pthread_join(id1, NULL);
26         pthread_join(id2, NULL);
27         return 0;
28 }

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2009-11-19 00:11 |只看該作者
我啥也不說了。
唉。大家可以不用回答此問題了。
都是當(dāng)時老師講譚的C程序設(shè)計(jì)的時候全局變量沒怎么聽。
剛剛翻看譚哥的書一看。原來如此。
extern
您需要登錄后才可以回帖 登錄 | 注冊

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP