efengyu 发表于 2006-4-29 16:55:47

创建线程求救

小弟写了个程序想验证一下,但总是有这种错误
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>

void task(int *counter)
{
fprintf(stderr,"task runing\n");
}

int arg;
static pthread_t tid;

int main()
{
int ret=pthread_create(&tid,NULL,task,(void*)&arg);
if(ret)
{
    fprintf(stderr,"success\n");
}
}


# gcc main.c -o main
main.c: In function `main':
main.c:15: warning: passing arg 3 of `pthread_create' from incompatible pointer
type
/tmp/cc67xs1l.o(.text+0x40): In function `main':
: undefined reference to `pthread_create'
collect2: ld returned 1 exit status

那位兄弟能给我解释一下,多谢了

moonhalf 发表于 2006-4-30 09:19:36


gcc -o main main.c -lpthread

genius-wh 发表于 2010-8-15 13:41:28

子程序类型应该是void * 即void * task(int *counter)

JCheung 发表于 2010-8-30 12:12:56

恩 ,楼上说的对
改成void *task(int *conunter)

好好看下函数原形就可以解决的问题。
页: [1]
查看完整版本: 创建线程求救