作者wanilly (我恨你!)
看板C_and_CPP
標題[語法] 關於pthread
時間Sat Mar 14 14:24:18 2009
下面為一個簡單的範例 使用pthread
我在網路上看到的簡單範例
但是我在linux下編譯卻無法通過
請問一下我是不是遺漏了什麼(編譯上)
我想程式碼應該不會有錯誤 因為是網路上的範例
謝謝
============================
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void print_message_function( void *ptr );
int main(void)
{
pthread_t thread1, thread2;
char *message1 = "Hello";
char *message2 = "World";
pthread_create(&thread1, pthread_attr_default,
(void*)&print_message_function, (void*) message1);
pthread_create(&thread2, pthread_attr_default,
(void*)&print_message_function, (void*) message2);
return 0;
}
void print_message_function( void *ptr )
{
char *message;
message = (char *) ptr;
printf("%s ", message);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.217.7
1F:推 ledia:沒 link pthread library ? 好歹給點錯誤訊息嘛 03/14 14:31
2F:→ ledia:不然這 code 我編得過也能正常執行 03/14 14:32
3F:→ wanilly:請問一下要怎麼link 03/14 15:13
4F:→ james732:gcc filename.c -lpthread (好像是...) 03/14 15:43