QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2156|回复: 3

创建线程求救

[复制链接]
发表于 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");
  }
}  


[root@localhost testdir]# 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

那位兄弟能给我解释一下,多谢了
发表于 2006-4-30 09:19:36 | 显示全部楼层
[code:1]
gcc -o main main.c -lpthread
[/code:1]
回复

使用道具 举报

发表于 2010-8-15 13:41:28 | 显示全部楼层
子程序类型应该是void * 即void * task(int *counter)
回复

使用道具 举报

发表于 2010-8-30 12:12:56 | 显示全部楼层
恩 ,楼上说的对
改成void *task(int *conunter)

好好看下函数原形就可以解决的问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-27 01:15 , Processed in 0.091771 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表