Re: [Kicad-developers] Warning regarding global wxStrings and thread-safety

2018-08-02 Thread Tomasz Wlostowski
On 02/08/18 19:01, Jeff Young wrote:
> I finally caught a long-standing but very infrequent crash in the
> debugger.  It’s somewhat harrowing.
> 
> wxString keeps multiple iterators on a string up-to-date with regard to
> editing.  It keeps them in a linked list.  If you reference a global
> string in a thread (/*even*/ in a const manner, such as taking its
> length), wxString will create an interator in your thread, link it into
> the list, and then unlink it when done (with no thread safety).  Sooner
> or later, this */will/* crash.

Hi Jeff,

I've been aware of this bug for quite a while (it manifested itself
during the development of multithreaded zone filler). I should have sent
a warning to the dev list, sorry for not doing that.

Cheers,
Tom

___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Kicad-developers] Warning regarding global wxStrings and thread-safety

2018-08-02 Thread Jeff Young
Interesting.  I also found this:

#if wxUSE_UNICODE_UTF8
  // NB: In UTF-8 build, (non-const) iterator needs to keep reference
  // to the underlying wxStringImpl, because UTF-8 is variable-length
  // encoding and changing the value pointer to by an iterator (using
  // its operator*) requires calling wxStringImpl::replace() if the old
  // and new values differ in their encoding's length.
  //
  // Furthermore, the replace() call may invalid all iterators for the
  // string, so we have to keep track of outstanding iterators and update
  // them if replace() happens.
  //
  // This is implemented by maintaining linked list of iterators for every
  // string and traversing it in wxUniCharRef::operator=(). Head of the
  // list is stored in wxString. (FIXME-UTF8)
At least they have a “FIXME” for it. :(

Cheers,
Jeff.

> On 2 Aug 2018, at 18:05, Seth Hillbrand  wrote:
> 
> Hi Jeff-
> 
> Good find.  I note here (http://docs.wxwidgets.org/3.0/classwx_string.html 
> ) that the use of wxString 
> is explicitly discouraged:
> 
> "While the use of wxString is unavoidable in wxWidgets program, you are 
> encouraged to use the standard string classes std::string or std::wstring in 
> your applications and convert them to and from wxString only when interacting 
> with wxWidgets."
> 
> I imagine that this or similar is what they had in mind.
> 
> -S
> 
> Am Do., 2. Aug. 2018 um 10:02 Uhr schrieb Jeff Young  >:
> I finally caught a long-standing but very infrequent crash in the debugger.  
> It’s somewhat harrowing.
> 
> wxString keeps multiple iterators on a string up-to-date with regard to 
> editing.  It keeps them in a linked list.  If you reference a global string 
> in a thread (even in a const manner, such as taking its length), wxString 
> will create an interator in your thread, link it into the list, and then 
> unlink it when done (with no thread safety).  Sooner or later, this will 
> crash.
> 
> This is the offending line:
>wxString wildcard = wxT( "*." ) + KiCadFootprintFileExtension;
> Looks innocuous enough, doesn’t it?
> 
> Anyway, something to keep in mind….
> ___
> Mailing list: https://launchpad.net/~kicad-developers 
> 
> Post to : kicad-developers@lists.launchpad.net 
> 
> Unsubscribe : https://launchpad.net/~kicad-developers 
> 
> More help   : https://help.launchpad.net/ListHelp 
> 

___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Kicad-developers] Warning regarding global wxStrings and thread-safety

2018-08-02 Thread Seth Hillbrand
Hi Jeff-

Good find.  I note here (http://docs.wxwidgets.org/3.0/classwx_string.html)
that the use of wxString is explicitly discouraged:

"While the use of wxString is unavoidable in wxWidgets program, you are
encouraged to use the standard string classes std::string or std::wstring
in your applications and convert them to and from wxString only when
interacting with wxWidgets."

I imagine that this or similar is what they had in mind.

-S

Am Do., 2. Aug. 2018 um 10:02 Uhr schrieb Jeff Young :

> I finally caught a long-standing but very infrequent crash in the
> debugger.  It’s somewhat harrowing.
>
> wxString keeps multiple iterators on a string up-to-date with regard to
> editing.  It keeps them in a linked list.  If you reference a global string
> in a thread (*even* in a const manner, such as taking its length),
> wxString will create an interator in your thread, link it into the list,
> and then unlink it when done (with no thread safety).  Sooner or later,
> this *will* crash.
>
> This is the offending line:
>
>wxString wildcard = wxT( "*." ) + KiCadFootprintFileExtension;
>
> Looks innocuous enough, doesn’t it?
>
> Anyway, something to keep in mind….
> ___
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@lists.launchpad.net
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>
___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp


Re: [Kicad-developers] Warning regarding global wxStrings and thread-safety

2018-08-02 Thread Jeff Young
PS: I also have a strange sense of deja vue.  Did I discover this earlier and 
forget already, or is my mind just playing tricks on me?

> On 2 Aug 2018, at 18:01, Jeff Young  wrote:
> 
> I finally caught a long-standing but very infrequent crash in the debugger.  
> It’s somewhat harrowing.
> 
> wxString keeps multiple iterators on a string up-to-date with regard to 
> editing.  It keeps them in a linked list.  If you reference a global string 
> in a thread (even in a const manner, such as taking its length), wxString 
> will create an interator in your thread, link it into the list, and then 
> unlink it when done (with no thread safety).  Sooner or later, this will 
> crash.
> 
> This is the offending line:
>wxString wildcard = wxT( "*." ) + KiCadFootprintFileExtension;
> Looks innocuous enough, doesn’t it?
> 
> Anyway, something to keep in mind….
> ___
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@lists.launchpad.net
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp

___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp


[Kicad-developers] Warning regarding global wxStrings and thread-safety

2018-08-02 Thread Jeff Young
I finally caught a long-standing but very infrequent crash in the debugger.  
It’s somewhat harrowing.

wxString keeps multiple iterators on a string up-to-date with regard to 
editing.  It keeps them in a linked list.  If you reference a global string in 
a thread (even in a const manner, such as taking its length), wxString will 
create an interator in your thread, link it into the list, and then unlink it 
when done (with no thread safety).  Sooner or later, this will crash.

This is the offending line:
   wxString wildcard = wxT( "*." ) + KiCadFootprintFileExtension;
Looks innocuous enough, doesn’t it?

Anyway, something to keep in mind….___
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kicad-developers
More help   : https://help.launchpad.net/ListHelp