Note: I am using the open source Poco C++ libraries
I have a parent thread that creates many child threads to deal with incoming connections, each of these child threads maintains an XML document, which the parent thread can request at anytime via callback. Therefore I have a mutex protecting this document.
My problem arises in that when I create an instance of my child thread (which is implemented as a class), I create the document and lock the mutex until the document is initialized (after starting the thread and getting some input from the user connection). When the initilization is complete, I unlock the mutex, and get an exception: Cannot unlock mutex. I realize now that this is because I technically locked it in the master thread.
What I am looking for ideas for is a threadsafe way to initialize my XMLDocument and have control of the mutex in the child thread.