Discussion:
stack overflow when using pthreads
Vijay Ponnavolu
2003-11-12 20:48:20 UTC
Permalink
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, &param);
param.sched_priority = PRI_FIFO_MAX;
pthread_attr_setschedparam(&attr, &param );

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
Vadim Zeitlin
2003-11-12 23:09:37 UTC
Permalink
On Wed, 12 Nov 2003 15:48:20 -0500 Vijay Ponnavolu <***@med.umich.edu> wrote:

VP> I wrote an application where the main() function forks of a thread
VP> which has wxentry as the starting point(so this thread is wholly
VP> resposible for all the wxwindows part). But what happened was that I had
VP> a stack overflow and the program crashed.

Can you see where does it crash? I.e. stack overflow is usually due
infinite recursion, is this the case here?

Or maybe threads really have a too small stack size by default under VMS,
I seem to remember that some platforms had this problem. What is the value
returned by pthread_attr_getstacksize()?

VZ


---------------------------------------------------------------------
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
Jason Heath
2003-11-12 23:56:32 UTC
Permalink
Hi,

I currently have a notebook (tab control) with various pages and on one of
the pages I wish to insert another notebook. The issues I am having is that
when inserting it, the tabs drawn are miniscule and then obviously do not
show their titles. I am using the initial frame (this) as the parent of the
first tab control, then the pages added of type wxNotebookPage (typedef of
wxWindow) use the tab control as the parent. The following tab control on a
page then uses the page itself (previously added to the first tab control)
as the parent and the newly created tabs use the second tab control. Could
someone please clear up why this isn't working? Thanks.

Jason


---------------------------------------------------------------------
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
Jason Heath
2003-11-13 00:27:22 UTC
Permalink
Ahhh, the control cannot be of wxDefaultSize...
so now it works


----- Original Message -----
From: "Jason Heath" <***@itiva.com>
To: <wx-***@lists.wxwindows.org>
Sent: Wednesday, November 12, 2003 3:56 PM
Subject: notebook (tab control) inside another notebook
Post by Jason Heath
Hi,
I currently have a notebook (tab control) with various pages and on one of
the pages I wish to insert another notebook. The issues I am having is that
when inserting it, the tabs drawn are miniscule and then obviously do not
show their titles. I am using the initial frame (this) as the parent of the
first tab control, then the pages added of type wxNotebookPage (typedef of
wxWindow) use the tab control as the parent. The following tab control on a
page then uses the page itself (previously added to the first tab control)
as the parent and the newly created tabs use the second tab control.
Could
Post by Jason Heath
someone please clear up why this isn't working? Thanks.
Jason
---------------------------------------------------------------------
Please read http://www.wxwindows.org/mlhowto.htm before posting.
---------------------------------------------------------------------
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
vijay
2003-12-03 16:25:59 UTC
Permalink
Sorry for the late response ....I have answers to your questions and
some more of my questions below :)
Post by Vadim Zeitlin
VP> I wrote an application where the main() function forks of a thread
VP> which has wxentry as the starting point(so this thread is wholly
VP> resposible for all the wxwindows part). But what happened was that I had
VP> a stack overflow and the program crashed.
Can you see where does it crash?I.e. stack overflow is usually due
infinite recursion, is this the case here?
I have got around this problem, I will answer your questions
though....
It crashes right before i create a new thread.
I do not have any kind of recursion in my code.
Post by Vadim Zeitlin
Or maybe threads really have a too small stack size by default under VMS,
I seem to remember that some platforms had this problem. What is the value
returned by pthread_attr_getstacksize()?
The stack size by default is 16200.

The other thing I tried was to have docview example run using
pthreads. This is what I did ...

I replaced IMPLEMENT_APP with IMPLEMENT_APP_NO_MAIN and I have a main
function which forks one single thread with the function "gui_thread"
as its starting point, in which I call wxEntry. (I had the initial
pthread stack size doubled to overcome the stack overflow we discussed
above)

What happens is ....
The window shows up initially fine but when I try to use the menu
option ....program crashes and the error is the same "---stack
overflow---"
It works fine if I incrrease the stack size again.
Something however seems to be fishy here ..... Is this behaviour
alright.

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
Loading...