The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Pthread_create issue Hellboy High Level Programming 1 05-19-2008 03:58 AM
How Can I use pthread_create ? shvalb High Level Programming 5 03-11-2008 10:17 AM
undefined reference to `pthread_create' netman High Level Programming 2 01-28-2008 09:31 AM
pthread_create and scope usage jenmead High Level Programming 3 09-20-2006 01:16 PM
pthread_create problem _rocky High Level Programming 5 03-11-2005 03:38 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-09-2006
Registered User
 

Join Date: Feb 2006
Posts: 34
unresolve pthread_create etc

how to do with that?

after cc -o xxxx xxxx.c



ld:
Unresolved:
_pthread_create
_pthread_deteach
_pthread_exit


Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 02-10-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
Code:
cc -o xxxx xxxx.c -lpthread
Reply With Quote
  #3  
Old 02-11-2006
Registered User
 

Join Date: Feb 2006
Posts: 34
Thanks

I want to print '*' and '0'. But after executing the program , no any response.
Whoud you please look at my codes, it's simple. However it is my first coding in unix enviroment. I am not stong in C++. I think something wrong.

#include<pthread.h>
#include<stdio.h>
int num_pthreads = 2;

void *PrintStar(void *arg)
{
int i,count,row;

for (count = 1,row =1;row<11; row++,count++)
{
for (i = 0; i < count; i++)
{
printf("*");
fflush(NULL);
sleep(1);
}
printf("\n");
sleep(1);
}
return NULL;
}

void *PrintNum(void *arg)
{
int i, count, row;

for(count = 1,row = 1; row<11; row++, count++)
{
for (i = 0; i<count; i++)
{
printf("0");
fflush(NULL);
sleep(1);
}
printf("\n");
sleep(1);
}
return NULL;
}

/********* this is the main thread's code */
int main()
{
pthread_t thread; /* holds thread info */
int i;

/* create the threads */
for (i = 0; i<num_pthreads;i++)
{
if(pthread_create(&thread,NULL,PrintStar,NULL))
printf("error creating a new thread PrintStar \n");
exit(1);
}
pthread_detach(thread);


for (i = 0; i<num_pthreads;i++)
{
if(pthread_create(&thread,NULL,PrintNum,NULL))
printf("error creating a new thread PrintNum \n");
exit(1);
}
pthread_detach(thread);

pthread_exit(NULL);
}
Reply With Quote
  #4  
Old 02-13-2006
linuxpenguin's Avatar
Registered User
 

Join Date: May 2002
Location: India
Posts: 295
for (i = 0; i<num_pthreads;i++)
{
if(pthread_create(&thread,NULL,PrintStar,NULL))
printf("error creating a new thread PrintStar \n");
exit(1);
}
pthread_detach(thread);

why is that exit there ?
I suppose you want to put it in the if block !! Something like this, ( note the additional braces after the if and efter the exit statement.

for (i = 0; i<num_pthreads;i++)
{
if(pthread_create(&thread,NULL,PrintStar,NULL)) {
printf("error creating a new thread PrintStar \n");
exit(1);
}
}
pthread_detach(thread);
__________________
War doesnt determine who is right, it determines who is left
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0