A
asit
This is the code snippet with main function..
#include <stdio.h>
#include <pthread.h>
pthread_t ntid;
void printids(const char *s) {
pid_t pid;
pthread_t tid;
pid = getpid();
tid = pthread_self();
printf("%s pid %u tid %u (0x%x) \n", s, (unsigned int)pid, (unsigned
int)tid, (unsigned int)tid);
}
void * thr_fn(void *arg) {
printids("new thread : ");
return ((void*)0);
}
int main() {
int err;
err = pthread_create(&ntid, NULL, thr_fn, NULL);
if(err != 0)
printf("can't create thread \n");
printids("main thread : ");
sleep(1);
return 0;
}
When I tried to compile this, it showed the following error ???
asit@asit-desktop:~/cpp$ gedit pthread1.c
asit@asit-desktop:~/cpp$ gcc -o pthread1 pthread1.c
/tmp/ccgO2hyj.o: In function `main':
pthread1.c.text+0x85): undefined reference to `pthread_create'
collect2: ld returned 1 exit status
#include <stdio.h>
#include <pthread.h>
pthread_t ntid;
void printids(const char *s) {
pid_t pid;
pthread_t tid;
pid = getpid();
tid = pthread_self();
printf("%s pid %u tid %u (0x%x) \n", s, (unsigned int)pid, (unsigned
int)tid, (unsigned int)tid);
}
void * thr_fn(void *arg) {
printids("new thread : ");
return ((void*)0);
}
int main() {
int err;
err = pthread_create(&ntid, NULL, thr_fn, NULL);
if(err != 0)
printf("can't create thread \n");
printids("main thread : ");
sleep(1);
return 0;
}
When I tried to compile this, it showed the following error ???
asit@asit-desktop:~/cpp$ gedit pthread1.c
asit@asit-desktop:~/cpp$ gcc -o pthread1 pthread1.c
/tmp/ccgO2hyj.o: In function `main':
pthread1.c.text+0x85): undefined reference to `pthread_create'
collect2: ld returned 1 exit status