LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-29-2003, 08:47 AM   #1
c12ayon
LQ Newbie
 
Registered: Oct 2003
Posts: 28

Rep: Reputation: 15
help needed here...


why it never reach the second thread?
=============================================
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>

void fireInTheHole(void);
static int accnt1, accnt2;

int main(){
accnt1=0;
accnt2=0;

pthread_t thread1, thread2;
pthread_create(&thread1, NULL, (void*)fireInTheHole, NULL);
pthread_create(&thread2, NULL, (void*)fireInTheHole, NULL);

printf("Thread join\n:");
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);

return 0;
}

void fireInTheHole(){
int counter = 0;
int tmp1, tmp2, r;
do {
tmp1 = accnt1;
tmp2 = accnt2;
r = rand();
accnt1 = tmp1 + r;
accnt2 = tmp2 - r;
counter ++;
} while (accnt1 + accnt2 == 0);

printf("Stopped w/ counter value: %d\n", counter);
printf("accnt1 = %d\naccnt2 = %d\n", accnt1,accnt2);
}
=============================================
 
Old 10-29-2003, 09:55 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
Are you talking about pthread_join?
 
Old 10-29-2003, 10:59 AM   #3
c12ayon
LQ Newbie
 
Registered: Oct 2003
Posts: 28

Original Poster
Rep: Reputation: 15
yes...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help needed sailu_mvn Programming 2 03-24-2005 06:50 AM
Help needed! =) kith Linux - General 14 02-10-2004 12:44 PM
help needed with QT sabeel_ansari Programming 1 01-21-2004 02:14 PM
C++ help needed sabeel Programming 6 11-27-2003 12:19 PM
Needed Help rajesh.s Linux - Hardware 0 12-17-2002 02:18 AM


All times are GMT -5. The time now is 01:56 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration