|
Prev: wxTreeCtrl
Next: wxWidget
From: "Dmytry Lavrov" on 10 Apr 2006 06:51 Hello, While debugging some application i'm are developing, i have noticed something strange: sometimes several events is sent simultaneously (i.e. in different threads), and in result some things can go corrupted (namely i had problems with wxTreeCtrl when event handler for delete key happened to be called more than one time resulting in corruption of data structures) I'm not starting any threads myself, and was at first puzzled by random crashes in application, that looked like multithreading issues. Is it correct behavior or not? Is there any possibility to disable this behavior? It seems to me that it could be the cause of many intrackable "random" crashes of applications, as most of code in event handlers is not threadsafe. Currently, as workaround, i have overrided ProcessEvent and made it TryLock mutex at entry and Unlock at leave (when i tried to use Lock rather than TryLock application started to freeze sometimes). It also confirmed my suspicion that it is indeed called simultaneously: i often get wxMUTEX_BUSY when locking mutex. I'm using wxGTK 2.6.2 by the way. --------------------------------------------------------------------- To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org
From: Alexander Vassilev on 10 Apr 2006 08:22 Well, ProcessEvent() by definition is _not_ thread-safe. You should use AddPendingEvent() instead. Regards Alex Dmytry Lavrov wrote: >Hello, > >While debugging some application i'm are developing, i have noticed >something strange: sometimes several events is sent simultaneously >(i.e. in different threads), and in result some things can go >corrupted (namely i had problems with wxTreeCtrl when event handler >for delete key happened to be called more than one time resulting in >corruption of data structures) >I'm not starting any threads myself, and was at first puzzled by >random crashes in application, that looked like multithreading issues. > >Is it correct behavior or not? Is there any possibility to disable >this behavior? It seems to me that it could be the cause of many >intrackable "random" crashes of applications, as most of code in event >handlers is not threadsafe. > >Currently, as workaround, i have overrided ProcessEvent and made it >TryLock mutex at entry and Unlock at leave (when i tried to use Lock >rather than TryLock application started to freeze sometimes). It also >confirmed my suspicion that it is indeed called simultaneously: i >often get wxMUTEX_BUSY when locking mutex. > >I'm using wxGTK 2.6.2 by the way. > >--------------------------------------------------------------------- >To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org >For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org
From: "Dmytry Lavrov" on 10 Apr 2006 09:36 Well, thing is, I'm not calling ProcessEvent myself, and again i *do not* start any threads. ProcessEvent is called by wxWidgets when there is some event. If ProcessEvent is in general not thread-safe it means that wxWidgets are calling non-threadsafe code from different threads. My current workaround is: bool ControlTreeView::ProcessEvent(wxEvent &event){ wxMutexError mutex_error; bool result=false; mutex_error=my_mutex_process_event.TryLock(); LogMutexError(mutex_error);// simply outputs mutex_error to the log if(mutex_error==wxMUTEX_NO_ERROR){ result=wxView::ProcessEvent(event); mutex_error=my_mutex_process_event.Unlock(); LogMutexError(mutex_error); } return result; }; and the only purprose of this workaround is to not let wxWidgets call on different threads the usually non-threadsafe code in the event handler or my event functions (ones registered with EVT_xxxxx). What i'm are asking for is a: my OnXxxxx functions that are registered with EVT_xxxxx get called simultaneously by the wxWidgets. Is it normal or not? Coz it looks kind of like bug in wxWidgets especially since everyone talks about how non-threadsafe this function i . b: if it is normal, is there any cleaner way to somehow prevent that. On 4/10/06, Alexander Vassilev <avasilev(a)voipgate.com> wrote: > Well, ProcessEvent() by definition is _not_ thread-safe. You should use > AddPendingEvent() instead. > > Regards > Alex > > Dmytry Lavrov wrote: > > >Hello, > > > >While debugging some application i'm are developing, i have noticed > >something strange: sometimes several events is sent simultaneously > >(i.e. in different threads), and in result some things can go > >corrupted (namely i had problems with wxTreeCtrl when event handler > >for delete key happened to be called more than one time resulting in > >corruption of data structures) > >I'm not starting any threads myself, and was at first puzzled by > >random crashes in application, that looked like multithreading issues. > > > >Is it correct behavior or not? Is there any possibility to disable > >this behavior? It seems to me that it could be the cause of many > >intrackable "random" crashes of applications, as most of code in event > >handlers is not threadsafe. > > > >Currently, as workaround, i have overrided ProcessEvent and made it > >TryLock mutex at entry and Unlock at leave (when i tried to use Lock > >rather than TryLock application started to freeze sometimes). It also > >confirmed my suspicion that it is indeed called simultaneously: i > >often get wxMUTEX_BUSY when locking mutex. > > > >I'm using wxGTK 2.6.2 by the way. > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org > >For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org > For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org
From: "Dmytry Lavrov" on 10 Apr 2006 09:55 ohh, and more detailed explanations what i'm talking about: I'm writing relatively simple editor. I don't start any threads or do anything like that. I'm using wxGTK 2.6.2 on Linux. I have implemented member function OnTree1KeyDown() that is added to event table with EVT_TREE_KEY_DOWN() macro. It handles various keyboard operations on the tree such as deletion of selected item when delete key is pressed. I have noticed that sometimes if i hold down delete key for a while(tree has lot of items), my application crash on seemingly random calls to wxTreeCtrl member functions. After some debugging and addibng log stuff i have noticed that OnTree1KeyDown() get called simultaneously on different threads. (i did not even do anything with ProcessEvent at all, i don't start any threads myself, and this whole thing was surprising for me...) For test and to confirm my suspicion about threads, i tried to work around the issue by adding mutex that will prevent two threads from calling event functions simultaneously. Initially i put that in the OnTree1KeyDown() but later i placed it in ProcessEvent to fix same problem in different event functions (such as OnMouse, etc.) What i want to find out is 1: whever it is normal behavior for wxWidgets or bug in wxWidgets(i suspect latter) 2: is there any cleaner/better way to make wxWidgets not start several threads for events. On 4/10/06, Dmytry Lavrov <dmytryl(a)gmail.com> wrote: > Well, thing is, I'm not calling ProcessEvent myself, and again i *do > not* start any threads. > > ProcessEvent is called by wxWidgets when there is some event. > If ProcessEvent is in general not thread-safe it means that wxWidgets > are calling non-threadsafe code from different threads. > > My current workaround is: > bool ControlTreeView::ProcessEvent(wxEvent &event){ > wxMutexError mutex_error; > bool result=false; > mutex_error=my_mutex_process_event.TryLock(); > LogMutexError(mutex_error);// simply outputs mutex_error to the log > if(mutex_error==wxMUTEX_NO_ERROR){ > result=wxView::ProcessEvent(event); > mutex_error=my_mutex_process_event.Unlock(); > LogMutexError(mutex_error); > } > return result; > }; > > and the only purprose of this workaround is to not let wxWidgets call > on different threads the usually non-threadsafe code in the event > handler or my event functions (ones registered with EVT_xxxxx). > > What i'm are asking for is > a: my OnXxxxx functions that are registered with EVT_xxxxx get called > simultaneously by the wxWidgets. Is it normal or not? Coz it looks > kind of like bug in wxWidgets especially since everyone talks about > how non-threadsafe this function i . > b: if it is normal, is there any cleaner way to somehow prevent that. > > On 4/10/06, Alexander Vassilev <avasilev(a)voipgate.com> wrote: > > Well, ProcessEvent() by definition is _not_ thread-safe. You should use > > AddPendingEvent() instead. > > > > Regards > > Alex > > > > Dmytry Lavrov wrote: > > > > >Hello, > > > > > >While debugging some application i'm are developing, i have noticed > > >something strange: sometimes several events is sent simultaneously > > >(i.e. in different threads), and in result some things can go > > >corrupted (namely i had problems with wxTreeCtrl when event handler > > >for delete key happened to be called more than one time resulting in > > >corruption of data structures) > > >I'm not starting any threads myself, and was at first puzzled by > > >random crashes in application, that looked like multithreading issues. > > > > > >Is it correct behavior or not? Is there any possibility to disable > > >this behavior? It seems to me that it could be the cause of many > > >intrackable "random" crashes of applications, as most of code in event > > >handlers is not threadsafe. > > > > > >Currently, as workaround, i have overrided ProcessEvent and made it > > >TryLock mutex at entry and Unlock at leave (when i tried to use Lock > > >rather than TryLock application started to freeze sometimes). It also > > >confirmed my suspicion that it is indeed called simultaneously: i > > >often get wxMUTEX_BUSY when locking mutex. > > > > > >I'm using wxGTK 2.6.2 by the way. > > > > > >--------------------------------------------------------------------- > > >To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org > > >For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org > > For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org > > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org
|
Pages: 1 Prev: wxTreeCtrl Next: wxWidget |