| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"hande" |
| Date: |
17 Oct 2006 06:57:26 AM |
| Object: |
random numbers with threads |
Hi, I wrote a program with two threads playing a number guessing game.
one thread pick a number the other try to guess it. Also first thread
say try a lower or higher number. but my program crashes in defining
the bounds for generating random numbers.
For instance the first thread pick 35
the other say 19. he should pick a number bigger than 19. for now
that's ok. now second thread say 60. then first thread say lower
number. but my second thread is not like that. how i can define that
borders?
thanks a lot
.
|
|
| User: "Martin Steen" |
|
| Title: Re: random numbers with threads |
17 Oct 2006 07:12:01 AM |
|
|
hande wrote:
but my program crashes in defining
the bounds for generating random numbers.
What program?
What about posting some code?
.
|
|
|
| User: "hande" |
|
| Title: Re: random numbers with threads |
17 Oct 2006 07:12:48 AM |
|
|
Martin Steen wrote:
hande wrote:
but my program crashes in defining
the bounds for generating random numbers.
What program?
What about posting some code?
else if(num<gnum)
{
gnum=rand()%gnum;
temp2=gnum;
cout<<"Thread2: "<<gnum<<endl;
// pthread_mutex_unlock(&myMutex);
}
else if(num>gnum)
{
gnum=rand()%(100-gnum);
cout<<"Thread2: "<<gnum<<endl;
//pthread_mutex_unlock(&myMutex);
}
.
|
|
|
|
|
| User: "Jim Langston" |
|
| Title: Re: random numbers with threads |
17 Oct 2006 11:49:15 AM |
|
|
hande" <hcardak@gmail.com> wrote in message
news:1161086246.168674.219970@e3g2000cwe.googlegroups.com...
Hi, I wrote a program with two threads playing a number guessing game.
one thread pick a number the other try to guess it. Also first thread
say try a lower or higher number. but my program crashes in defining
the bounds for generating random numbers.
For instance the first thread pick 35
the other say 19. he should pick a number bigger than 19. for now
that's ok. now second thread say 60. then first thread say lower
number. but my second thread is not like that. how i can define that
borders?
thanks a lot
First, try your program without the threads. See if it works that way. If
it does, then it's a threading issue and post some code at:
comp.programming.threads that is small enough to show the problem.
If it does not without the threads, it's a C++ error, post the smallest code
here that compiles that wll show the error.
.
|
|
|
|

|
Related Articles |
|
|