Re: [xml] xmlNewTextWriterFilename Win32 Problem



Coleman Brumley wrote:

I have a strange problem with xmlNewTextWriterFilename on Win32.

I believe that your problem is related to multi-threading, not libxml
per se.

I have two file name strings:
char outname[MAX_PATH]={(char)0};
static char fname[MAX_PATH]={(char)0};

Are they global or local variables? The static keyword has two different
meanings for these two cases.

outname gets passed to a function XMLWriteData(const char *file) which in turn calls xmlNewTextWriterFilename(file,0);. As long as the fname variable (which gets passed to XMLReadData via the CreateThread function) is static, xmlNewTextWriterFilename crashes and generates an access violoation in NTDLL.
As soon as I change the declarations to:
char outname[MAX_PATH]={(char)0};
/*static*/ char fname[MAX_PATH]={(char)0};

xmlNewTextWriteFilename works fine.

I am going to assume that fname is a local variable. You can think of
a static local variable as a global variable that cannot be seen from
outside the function where it is defined.

The point is that only one buffer exist in memory for fname. If you
change the contents of fname, it will affect all threads. This can lead
to strange behavior. So given the above information, my guess is that
the observed behavior occurs because you access a shared resource
(fname) from multiple threads without any synchronization.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]