compile error:c language in telnet(linux)
Posted
by lilyrose07
on Stack Overflow
See other posts from Stack Overflow
or by lilyrose07
Published on 2010-04-28T15:17:23Z
Indexed on
2010/04/28
15:23 UTC
Read the original article
Hit count: 114
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<pthread.h>
int count=0;
void *thread_function(void *arg)
{
while(count<10)
{
if(count%2==1)
{
count++;
}
else
{sleep(1);}
}
}
int main(int argc,int *argv)
{
int res;
pthread_t a_thread[2];
void *thread_result;
int n;
while(count<10)
{
if(count%2==0)
{printf("%d",count);
count++;
}
else{sleep(1);}
}
for(n=0;n<2;n++)
{
pthread_create(&(a_thread[n]),NULL,thread_function,NULL);
}
while(count==9)
{pthread_join(a_thread[0],&thread_result);
}
while(count==10)
{
pthread_join(a_thread[1],&thread_result);
}
printf("%d",count);
return 0;
}
in telnet,linux
i write gcc za.c
error list: undefined reference to pthread_create,pthread_join in function 'main'
//why??
© Stack Overflow or respective owner