|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
strange behavior with threads...Hi!
I've the following code : void _Window::Start(void* arg) { ThreadArgs args; args.TheWindow=this; args.args=arg; int err = pthread_create(&main_thread,NULL,_Start, (void*)&args); if (err) { throw new Exception(err, "window thread creation error"); } } void* _Window::_Start(void* arg) { ThreadArgs* args = (ThreadArgs*) arg; pthread_exit((void*)args->TheWindow->start_routine(args->args)); } _Window::_Start is static for some reason that I can't determine it happens that args in _Window::_Start have strange value (args->TheWindow don't contain a valid pointer, ie a pointer on a _Window object) this happens on 2 thread configuration upon creation of the second thread (1rst thread is main() and do only create the Window and sleep) It happens randomly and backtrace on crash don't contain any usefull information (looks exactly like the one when args->TheWindow is correct) I didn't tested on other posix system thanks for your help Regards JLM -- KISS! (Keep It Simple, Stupid!) (garde le simple, imbécile!) "mais qu'est-ce que tu m'as pondu comme usine à gaz? fait des choses simples et qui marchent, espèce d'imbécile!" ----------------------------- "Si vous pensez que vous êtes trop petit pour changer quoique ce soit, essayez donc de dormir avec un moustique dans votre chambre." Betty Reese http://www.grainesdechangement.com/citations.htm -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple |
|
|
Re: strange behavior with threads...On Jul 23 15:50, jean-luc malet wrote:
> Hi! > I've the following code : > void _Window::Start(void* arg) > { > ThreadArgs args; > args.TheWindow=this; > args.args=arg; > int err = pthread_create(&main_thread,NULL,_Start, (void*)&args); > if (err) > { > throw new Exception(err, "window thread creation error"); > } > } > void* _Window::_Start(void* arg) > { > ThreadArgs* args = (ThreadArgs*) arg; > pthread_exit((void*)args->TheWindow->start_routine(args->args)); > } > > _Window::_Start is static > > for some reason that I can't determine it happens that args in > _Window::_Start have strange value (args->TheWindow don't contain a > valid pointer, ie a pointer on a _Window object) Maybe you shouldn't let the arg to the thread point to a local stack-based variable in the other method which, as you code implies, returns after having started the thread... Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple |
|
|
Re: strange behavior with threads...jean-luc malet wrote:
> Hi! > I've the following code : > void _Window::Start(void* arg) > { > ThreadArgs args; This allocates a ThreadArgs struct on the stack. > int err = pthread_create(&main_thread,NULL,_Start, (void*)&args); This passes a pointer to the ThreadArgs struct on the stack to the new thread. > if (err) > { > throw new Exception(err, "window thread creation error"); > } > } This then immediately exits and deallocates the stack frame, making the &args pointer you passed to the main_thread invalid. cheers, DaveK -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple |
|
|
Re: strange behavior with threads...On Thu, Jul 23, 2009 at 4:11 PM, Corinna
Vinschen<corinna-cygwin@...> wrote: > On Jul 23 15:50, jean-luc malet wrote: >> Hi! >> I've the following code : >> void _Window::Start(void* arg) >> { >> ThreadArgs args; >> args.TheWindow=this; >> args.args=arg; >> int err = pthread_create(&main_thread,NULL,_Start, (void*)&args); >> if (err) >> { >> throw new Exception(err, "window thread creation error"); >> } >> } >> void* _Window::_Start(void* arg) >> { >> ThreadArgs* args = (ThreadArgs*) arg; >> pthread_exit((void*)args->TheWindow->start_routine(args->args)); >> } >> >> _Window::_Start is static >> >> for some reason that I can't determine it happens that args in >> _Window::_Start have strange value (args->TheWindow don't contain a >> valid pointer, ie a pointer on a _Window object) > > Maybe you shouldn't let the arg to the thread point to a local > stack-based variable in the other method which, as you code implies, > returns after having started the thread... > > > Corinna > > -- > Corinna Vinschen Please, send mails regarding Cygwin to > Cygwin Project Co-Leader cygwin AT cygwin DOT com > Red Hat > > -- > Problem reports: http://cygwin.com/problems.html > FAQ: http://cygwin.com/faq/ > Documentation: http://cygwin.com/docs.html > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple > > Yes, sorry for such lame question :( I should have seen this issue the code has been modified and has been tested under linux and is now working as expected under linux, thanks however I have a X server connection issue freeglut (./tests/GENERATED/GlutWindowTest): Unable to create direct context rendering for window ' ' This may hurt performance. XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0" after 34 requests (32 known processed) with 5 events remaining. think I will have to post on Cygwin/X ML thanks for help JLM -- KISS! (Keep It Simple, Stupid!) (garde le simple, imbécile!) "mais qu'est-ce que tu m'as pondu comme usine à gaz? fait des choses simples et qui marchent, espèce d'imbécile!" ----------------------------- "Si vous pensez que vous êtes trop petit pour changer quoique ce soit, essayez donc de dormir avec un moustique dans votre chambre." Betty Reese http://www.grainesdechangement.com/citations.htm -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple |
|
|
Re: strange behavior with threads...I receive the same error when running ubuntu in a virtual environment and everything I have found regarding that issue points to either improper configuration of xorg.conf for multiple video cards or video cards that don't support OpenGL. |
|
|
Re: strange behavior with threads...On Fri, Jul 24, 2009 at 8:43 PM, benadam777<benadam7777@...> wrote:
> > > > jean-luc malet wrote: >> >> I have a X server connection issue >> >> freeglut (./tests/GENERATED/GlutWindowTest): Unable to create direct >> context rendering for window ' ' >> This may hurt performance. >> XIO: fatal IO error 11 (Resource temporarily unavailable) on X server >> ":0.0" >> after 34 requests (32 known processed) with 5 events remaining. >> >> > > I receive the same error when running ubuntu in a virtual environment and > everything I have found regarding that issue points to either improper > configuration of xorg.conf for multiple video cards or video cards that > don't support OpenGL. > -- I just tried with ubuntu in a virtual environment and everything run fine, seems to come from cygwin/X.... Best Regards, JLM -- KISS! (Keep It Simple, Stupid!) (garde le simple, imbécile!) "mais qu'est-ce que tu m'as pondu comme usine à gaz? fait des choses simples et qui marchent, espèce d'imbécile!" ----------------------------- "Si vous pensez que vous êtes trop petit pour changer quoique ce soit, essayez donc de dormir avec un moustique dans votre chambre." Betty Reese http://www.grainesdechangement.com/citations.htm -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple |
| Free embeddable forum powered by Nabble | Forum Help |