[Expat-discuss] XMLParse Handlers

Karl Waclawek karl@waclawek.net
Sun Nov 3 16:46:41 2002


> Actually, what I did is made the startElement and endElement methods
> static, and passed the "this" pointer as the User data.  However, I'm
> thinking that there might be possible threading issues here.  Is this
> worry warranted?  If so, I've never dealt with threads in C++, how would
> this situation be "synchronized?"

An Expat parser instance should only be used from within a thread.
That is, calling XML_Parse(Buffer), setting handlers and such is not thread safe.

However, if the handlers passed to Expat are themselves thread-safe
then that should be OK, since the call direction is reversed, i.e.
Expat is not the callee, but the caller.

Now, if you need to call XML_Parse(Buffer) from different threads then
you should wrap the call into another call which can be made thread-safe,
e.g. using critical sections or mutexes. But I am no expert on
how to use those in C++.

> (and thanks for the link, I checked out the OO wrappers, and they look
> good, but I'll try the above method first since I already wrote a lot of
> code that way)

It seems the most current wrapper is Arabica, btw.

Karl