#1  
Old 14th August 2008, 13:28
full_adder full_adder is offline
Junior Member
 
Join Date: Feb 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default HELP in a Thread code

Hi everyone

I wrote the following code from an OS book. But when I compiled it the following msg had appeared:

In function 'main': undefined reference to 'pthread_create'
In function 'main': undefined reference to 'pthread_join'

I don't understand what it means exactly!!



Code:
#include<pthread.h>
#include<stdio.h>
int sum;
void* runner(void *param);
int main(int argc, char *argv[]){
	pthread_t tid;
	pthread_attr_t attr;

	if(argc !=2){
		printf("usage: a.out <int value>\n");
		return -1;
	}
	if( atoi(argv[1]) < 0 ){
		printf("%d must be >= 0\n",atoi(argv[1]));
		return -1;
	}
	pthread_attr_init(&attr);
	pthread_create(&tid,&attr,(void *)runner,(void *)argv[1]);
	pthread_join(tid,NULL);

	printf("sum = %d\n",sum);
}
void* runner(void *param){
	int i, upper=atoi(param);
	sum=0;
	for(i=1;i<=upper;i++)
		sum +=i;
	pthread_exit(0);
}
Reply With Quote
Sponsored Links
  #2  
Old 14th September 2008, 17:13
tempora tempora is offline
Junior Member
 
Join Date: Sep 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default solution

compile this code in the following way

gcc code.c -lpthread

where code.c is assumed to be the filename of your c code.


I have just registered to reply. i shall not be checking back. so, dont expect a reply. sorry for inconvenience.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail -Ubuntu 8.04 c4rdinal HOWTO-Related Questions 112 23rd August 2011 11:49
Virtual Users And Domains With Postfix, Courier And MySQL (Fedora 8) sparky121167 HOWTO-Related Questions 5 10th July 2008 15:43
amavis + spamassassin 4integration Installation/Configuration 4 13th September 2007 16:02
Dead spamassassin in ETCH Amavisd setup. Trapper HOWTO-Related Questions 10 24th July 2007 05:05
Can't get authenticated. kwinnuxbie HOWTO-Related Questions 1 29th October 2006 14:45


All times are GMT +2. The time now is 19:57.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.