for TinyXML is a good XMl libuary, i use it to save packet data in network transmission, such as the client receive some packet from the server in UDP muticast mode. client join more than one muticast groups, so it must create multi-thread to receive and write the data in different files(of course, the numbers of file equals the nums of muticast groups). i design a writeXML class which has a DoWrite(char*,size_t) function.
such as :
void DoWrite(char*,size_t)
{
boost::unique_lock<boost::mutex> lLock(m_lock);
lLock.lock();
}
but the problem is whenever the DoWrite function is called, the boost:lock_error comes. who can help me? tks very much! emphasized text
Remove lLock.lock();
from your code, boost::unique_lock
calls lock
on the passed in mutex for you, so you do not need to call it manually (you are calling lock twice on the mutex). From the reference:
unique_lock(Lockable & m)
Effects:
Stores a reference to m. Invokes m.lock().
Also, use boost::lock_guard
instead unless you want to defer acquiring the lock. See the documentation for more details.