wxConvFile (and wxFileExists) not thread safe on Mac
Stefan Csomor
csomor at advancedconcepts.ch
Tue Aug 28 23:18:14 PDT 2007
Hi Joost
>
> I'm encountering occasional crashes in the mac version of my app,
> related to the simultaneous use of wxFileExists in multiple threads.
> I've narrowed the problem down to the following test case:
>
> for(int i=0; i < 100000; i++)
> {
> wxConvFile.WC2MB(NULL, wxT("Test"), 0);
> }
>
> If this is executed in two threads simultaneously, an access violation
> occurs.
>
> wxConvFile is actually a global wxMBConv_macUTF8D object
> (strconv.cpp). It has three member variables, which are used
> internally in calls to OSX character set conversion functions.
> Apparently these members are modified during the conversion, causing a
> clash when multiple threads are doing a conversion simultaneously
> using the same global conversion object.
>
> Bottom line is that wxFileExists is not thread safe, and probably any
> function that accesses a file based on its file name!
>
> I'd like to fix it somehow, but I'm not familiar with the OSX specific
> functions used in wxMBConv_macUTF8D.
thanks for spotting this, unfortunately I haven't found any clues on
Apple's site as which parts of the implementation might not be thread
safe, do you always get the stack trace ?
Thanks,
Stefan
Joost wrote:
More information about the wx-users
mailing list