![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
unresolve pthread_create etc
how to do with that?
after cc -o xxxx xxxx.c ld: Unresolved: _pthread_create _pthread_deteach _pthread_exit Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
cc -o xxxx xxxx.c -lpthread |
|
#3
|
|||
|
|||
|
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); } |
|
#4
|
||||
|
||||
|
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 |
||||
| Google The UNIX and Linux Forums |