Hi!
I'm doing a simply program with threads.
I've got two classes MyApp and MyThread. In the last one I implements the thinks that have to do the thread. And in the first one I create two threads of MyThread class. I want to wait for finish MyApp that the two threads have been finished before. I do it with the instruccion thread1->Wait(). But I don't do it in the rigth way.
My code is this:
virtual ExitCode Entry ()
{
Saluda();
for ( m_count = 0; m_count < 10; m_count++ )
{
if ( TestDestroy() ){
break;
printf("\n Thread %hu
wxThread::Sleep(1000);
}
printf("\n Thread ha acabado.\n");
return (ExitCode)1;
}
bool MyApp::OnInit()
{
MyThread *thread1, *thread2;
thread1=new MyThread("\n Numero 1", 1);
thread1->SetPriority(WXTHREAD_DEFAULT_PRIORITY);
thread2=new MyThread("\n Numero 2", 2);
thread2->SetPriority(WXTHREAD_DEFAULT_PRIORITY);
//se ejecutan los thread creados
thread1->Run();
thread2->Run();
while ( (thread1->Wait()!= 1 and thread1->Wait()!= -1) or (thread2->Wait()!= 1 and thread2->Wait() != -1)){}
return true;
}
Can you help me?[/quote]
Thread Joinable
-
- Earned some good credits
- Posts: 120
- Joined: Sun Aug 29, 2004 3:09 pm
- Location: Grenoble, France
- Contact:
Hello.
As thread are based on the same class, why don't you put a static counter of running thread with one or two functions to access it (with mutexes) in order to count how many thread is running and you can wait (while) until all thread have returned.
As thread are based on the same class, why don't you put a static counter of running thread with one or two functions to access it (with mutexes) in order to count how many thread is running and you can wait (while) until all thread have returned.
What is little and green, witch go up and down ??
Yoda playing with the force.
Yoda playing with the force.
I'm sorry but I don't undertand you. 
Why I have to put a static counter?For what? I can't see the concept.
I don't count how many threads is running. I do a loop with a count for print a message only for to know that the programs run well.
Other way I try to do a loop for wait until thread have returned but... It doesn't work.
This is the first time I work with widget and I don't know very well how to use it.
Thanks

Why I have to put a static counter?For what? I can't see the concept.
I don't count how many threads is running. I do a loop with a count for print a message only for to know that the programs run well.
Other way I try to do a loop for wait until thread have returned but... It doesn't work.
This is the first time I work with widget and I don't know very well how to use it.
Thanks
Queen
-
- Earned some good credits
- Posts: 120
- Joined: Sun Aug 29, 2004 3:09 pm
- Location: Grenoble, France
- Contact:
Oh, excuse-me, as I see you write
I think you wana use many threads.
What I want to say is you count all thread you run and when it finish, you decrement.
When the count is zero, you can exit the app.
The wait function can not work as you use it because wxThread::wait() (1) wait until the thread stop.
1 : http://www.wxwidgets.org/manuals/2.6.2/ ... threadwait
Code: Select all
thread1->Run();
thread2->Run();
What I want to say is you count all thread you run and when it finish, you decrement.
When the count is zero, you can exit the app.
The wait function can not work as you use it because wxThread::wait() (1) wait until the thread stop.
1 : http://www.wxwidgets.org/manuals/2.6.2/ ... threadwait
What is little and green, witch go up and down ??
Yoda playing with the force.
Yoda playing with the force.