# Xml/libxml thread safety

**URL:** <https://www.ruby-forum.com/t/xml-libxml-thread-safety/71823>\
**Category:** Ruby\
**Created:** [October 11, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/xml-libxml-thread-safety/71823 "2006-10-11T18:59:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Mage](https://www.ruby-forum.com/u/Mage)\
**Post date:** [October 11, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/xml-libxml-thread-safety/71823/1 "2006-10-11T18:59:12Z")

</div>

Hello,

my simple question is that is libxml thread-safe? I would like to use it  
in production environment.

```
   Mage
```

---

<div class="post-metadata">

**Author:** ![Mage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Mage](https://www.ruby-forum.com/u/Mage)\
**Post date:** [October 12, 2006, 10:38am UTC](https://www.ruby-forum.com/t/xml-libxml-thread-safety/71823/2 "2006-10-12T10:38:51Z")

</div>

On Thu, 2006-10-12 at 01:58 +0900, Mage wrote:

> my simple question is that is libxml thread-safe? I would like to use it  
> in production environment.

(I assume you mean libxml-ruby, rather than libxml itself?)

The simple answer is probably not. We do have an open bug[1] regarding  
cross-thread synchronisation, and though I’ve been unable to reproduce  
it so far, I take that to mean it’s probably platform/configure/compiler  
specific. Most of the other open bugs pertain to pointer handling, and  
have the potential to get ‘interesting’ in a multi-threaded program.

I’m working on fixing most of this and implementing open feature  
requests for 0.4.0, but currently I’m short on free time and apparently  
kind of on my own on the project. I guess I might be able to give a more  
positive answer to the same question early next year…

Meanwhile, you might want to check out ruby-xml-smart:  
[http://raa.ruby-lang.org/project/ruby-xml-smart/](http://raa.ruby-lang.org/project/ruby-xml-smart/)

---

<div class="post-metadata">

**Author:** ![Mage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Mage](https://www.ruby-forum.com/u/Mage)\
**Post date:** [October 12, 2006, 3:18pm UTC](https://www.ruby-forum.com/t/xml-libxml-thread-safety/71823/3 "2006-10-12T15:18:00Z")

</div>

Ross B. wrote:

> On Thu, 2006-10-12 at 01:58 +0900, Mage wrote:
> 
> > my simple question is that is libxml thread-safe? I would like to use it  
> > in production environment.
> 
> (I assume you mean libxml-ruby, rather than libxml itself?)

True.

> The simple answer is probably not. We do have an open bug[1] regarding  
> cross-thread synchronisation, and though I’ve been unable to reproduce  
> it so far, I take that to mean it’s probably platform/configure/compiler  
> specific. Most of the other open bugs pertain to pointer handling, and  
> have the potential to get ‘interesting’ in a multi-threaded program.

I simply want to generate an xml file with root ‘ads’ and nodes ‘ad’  
(and subnodes of course).  
Since the generation uses network traffic and image manipulation I think  
multithreading will enchant the performance.

Should I create every ‘ad’ node with Monitor.synchronize? Is this  
enough? The subnodes of ‘ad’ nodes won’t share any data.

```
   Mage
```

---

<div class="post-metadata">

**Author:** ![Mage](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Mage](https://www.ruby-forum.com/u/Mage)\
**Post date:** [October 18, 2006, 10:38am UTC](https://www.ruby-forum.com/t/xml-libxml-thread-safety/71823/4 "2006-10-18T10:38:53Z")

</div>

On Thu, 2006-10-12 at 22:15 +0900, Mage wrote:

> > have the potential to get ‘interesting’ in a multi-threaded program.
> 
> I simply want to generate an xml file with root ‘ads’ and nodes ‘ad’  
> (and subnodes of course).  
> Since the generation uses network traffic and image manipulation I think  
> multithreading will enchant the performance.
> 
> Should I create every ‘ad’ node with Monitor.synchronize? Is this  
> enough? The subnodes of ‘ad’ nodes won’t share any data.

To be completely honest, I really don’t know - I’ve still to reproduce  
any multithread-related bugs here, but I _do_ know we have a few open  
problems that _could_ be exasperated in a multithreaded program. My only  
remotely useful advice right now would be “try it”, but then probably  
not in a production environment… The lib _should_ be thread safe, so  
if you do try it, and find anything goes wrong, I’d appreciate a bug  
report 😉

Sorry I can’t be more help… ☹
