tinyxml2 icon indicating copy to clipboard operation
tinyxml2 copied to clipboard

Is tinyxml2 thread-safe?

Open galoko opened this issue 6 years ago • 5 comments

I suppose I cannot work with same XMLDocument from different threads, this would be unreasonable if you ask me, but can I create two separate XMLDocument in two different threads so each thread would work with his own document?

galoko avatar Aug 05 '18 23:08 galoko

You can use a reference. Or you cannot?

slr69 avatar Aug 06 '18 18:08 slr69

What do you mean?

galoko avatar Aug 07 '18 20:08 galoko

Declare somewhere a XMLDocument and pass it's reference to your threads. When one of that theads needs to do something with xdoc don't forget to lock xdoc to prevent other thread to access xdoc.

slr69 avatar Aug 08 '18 06:08 slr69

No, no, you got it all wrong, what I meant to ask is: Would there be any interference between two threads, each working with its own instance of XMLDocument? Something like global variables or something similar inside tinyxml2 may cause that. I just wanted to make sure it's not going to happen.

galoko avatar Aug 08 '18 15:08 galoko

tinyxml2 is not thread-safe. This would add additional complexity to the code. But if you have two separate Documents in each thread there will be no conflicts.

You can use the XMLDocument::DeepClone function to get a deep copy of your XML document.

Armagetron avatar Oct 11 '18 08:10 Armagetron