Vijay Ponnavolu
2003-11-12 20:48:20 UTC
Hello,
I wrote an application where the main() function forks of a thread
which has wxentry as the starting point(so this thread is wholly
resposible for all the wxwindows part). But what happened was that I had
a stack overflow and the program crashed. I wrote this application on
VMS.
I have put the testcode below........ Without worrying about how to
come out of the GUI_thread to the main thread can anyone tell why I have
a stack overflow if I do not increase the stack size of the pthtread to
what it is now.
/*
* Global data
*/
pthread_mutex_t mutex_test = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_test = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex_main = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_main = PTHREAD_COND_INITIALIZER;
pthread_t threads[workers]; /* Array of worker threads */
int data_test = 0;
int show_menu=0;
char **arg2;
IMPLEMENT_APP_NO_MAIN(MyApp)
void *gui_thread (void* arg) {
wxEntry(1,arg2);
return arg;
}
bool MyApp::OnInit()
{
printf("start of Oninit function\n");
// Create the main window
MyFrame *frame = new MyFrame( wxT("Multi Thread Test"));
frame->SetSize(-1, -1, 500,500);
SetTopWindow(frame);
frame->Show(TRUE);
return TRUE;
}
int main(int argc, char **argv) {
int a;
int worker_num; /* Counter used when indexing workers */
void *exit_value; /* Individual worker's return status */
int status; /* Hold status from pthread calls */
int temp =1;
size_t stacksize;
int choice;
char c_choice;
pthread_attr_t attr;
struct sched_param param;
pthread_attr_init (&attr);
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
pthread_attr_getschedparam ( &attr, ¶m);
param.sched_priority = PRI_FIFO_MAX;
pthread_attr_setschedparam(&attr, ¶m );
pthread_attr_getstacksize ( &attr, &stacksize);
stacksize = stacksize *2;
pthread_attr_setstacksize ( &attr, stacksize);
arg2 = argv;
worker_num = 0;
status = pthread_create ( &threads[worker_num], &attr,
gui_thread, (void *)worker_num);
printf("\nBack to Main Thread\n");
printf("To switch back to the gui thread press g\nTo
quit from application press q\nElse continue\n");
c_choice = getchar();
while(c_choice!='q'){
printf("choice:%c\n",c_choice);
if(c_choice == 'g'){
printf("Waking up the gui thread\n");
pthread_cond_signal(
&cond_test);
fflush(stdin);
}
else if(c_choice =='q')
exit(0);
printf("\nBack to Main Thread\n");
printf("To switch back to the gui thread press g\nTo
quit from application press q\nElse continue\n");
c_choice = getchar();
}
printf("Total Exit\n");
return 1;
}
Thanks in advance,
VJ
---------------------------------------------------------------------
Please read http://www.wxwindows.org/mlhowto.htm before posting.
To unsubscribe, e-mail: wx-users-***@lists.wxwindows.org
For additional commands, e-mail: wx-users-***@lists.wxwindows.org
I wrote an application where the main() function forks of a thread
which has wxentry as the starting point(so this thread is wholly
resposible for all the wxwindows part). But what happened was that I had
a stack overflow and the program crashed. I wrote this application on
VMS.
I have put the testcode below........ Without worrying about how to
come out of the GUI_thread to the main thread can anyone tell why I have
a stack overflow if I do not increase the stack size of the pthtread to
what it is now.
/*
* Global data
*/
pthread_mutex_t mutex_test = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_test = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex_main = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_main = PTHREAD_COND_INITIALIZER;
pthread_t threads[workers]; /* Array of worker threads */
int data_test = 0;
int show_menu=0;
char **arg2;
IMPLEMENT_APP_NO_MAIN(MyApp)
void *gui_thread (void* arg) {
wxEntry(1,arg2);
return arg;
}
bool MyApp::OnInit()
{
printf("start of Oninit function\n");
// Create the main window
MyFrame *frame = new MyFrame( wxT("Multi Thread Test"));
frame->SetSize(-1, -1, 500,500);
SetTopWindow(frame);
frame->Show(TRUE);
return TRUE;
}
int main(int argc, char **argv) {
int a;
int worker_num; /* Counter used when indexing workers */
void *exit_value; /* Individual worker's return status */
int status; /* Hold status from pthread calls */
int temp =1;
size_t stacksize;
int choice;
char c_choice;
pthread_attr_t attr;
struct sched_param param;
pthread_attr_init (&attr);
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
pthread_attr_getschedparam ( &attr, ¶m);
param.sched_priority = PRI_FIFO_MAX;
pthread_attr_setschedparam(&attr, ¶m );
pthread_attr_getstacksize ( &attr, &stacksize);
stacksize = stacksize *2;
pthread_attr_setstacksize ( &attr, stacksize);
arg2 = argv;
worker_num = 0;
status = pthread_create ( &threads[worker_num], &attr,
gui_thread, (void *)worker_num);
printf("\nBack to Main Thread\n");
printf("To switch back to the gui thread press g\nTo
quit from application press q\nElse continue\n");
c_choice = getchar();
while(c_choice!='q'){
printf("choice:%c\n",c_choice);
if(c_choice == 'g'){
printf("Waking up the gui thread\n");
pthread_cond_signal(
&cond_test);
fflush(stdin);
}
else if(c_choice =='q')
exit(0);
printf("\nBack to Main Thread\n");
printf("To switch back to the gui thread press g\nTo
quit from application press q\nElse continue\n");
c_choice = getchar();
}
printf("Total Exit\n");
return 1;
}
Thanks in advance,
VJ
---------------------------------------------------------------------
Please read http://www.wxwindows.org/mlhowto.htm before posting.
To unsubscribe, e-mail: wx-users-***@lists.wxwindows.org
For additional commands, e-mail: wx-users-***@lists.wxwindows.org