We are using Xerces-C1_4 on a two-processor Sun box running Solaris 8. There
appears to be no problem in a single-threaded app, however, a multi-threaded
app fails. I have created a test code that makes simple Xerces calls and
which fails in a multi-threaded environment. The test code can be run
independently and is as follows (also included is a stack trace when the app
fails):
----------------------------------------------------------------------------
--
// thrTest.cpp
#include <iostream>
#include <util/PlatformUtils.hpp>
#include <dom/DOM.hpp>
#include <parsers/DOMParser.hpp>
#include <framework/MemBufInputSource.hpp>
#include <pthread.h>
#define MAXTESTTHREADS 512
void* worker(void* arg);
int main(int argc, char *argv[]) {
if(argc == 2) {
int numThreads = atoi(argv[1]);
if(numThreads > MAXTESTTHREADS)
return -1;
std::cout << "Testing file for " << numThreads << "
threads.\n";
XMLPlatformUtils::Initialize();
thread_t p_thread[MAXTESTTHREADS];
int ret = pthread_setconcurrency(20);
for(int num=0; num < numThreads ; num++)
pthread_create(&p_thread[num], NULL, worker, NULL);
for(int num=0; num < numThreads ; num++)
pthread_join(p_thread[num], NULL);
}
else {
std::cout << "Usage:\n\t thrTest <numOfThreads>\n";
}
return 0;
}
void* worker(void* arg) {
const XMLByte memChar[] =
"<config><item1><item2/></item1></config>";
char *fakeSysID = "fakeID";
for(int i = 0; i < 1000; i++) {
DOMParser parser;
MemBufInputSource memSource(memChar, sizeof(memChar)-1,
fakeSysID, false);
parser.parse(memSource);
DOM_Document domDoc = parser.getDocument();
}
return(NULL);
}
----------------------------------------------------------------------------
-----------
Here is a stack trace as well:
----------------------------
[1] XMLPlatformUtils::lockMutex(0x1, 0xc7868, 0xfe705794, 0xff138000,
0xff13e7b8, 0x0), at 0xff285350
[2] DOMStringHandle::operator new(0xc, 0x0, 0x0, 0x8, 0x0, 0x0), at
0xff2574ac
[3] DOMStringHandle::createNewStringHandle(0x7, 0x14bd4, 0xe1b84b74, 0x0,
0xff13e7b8, 0x0), at 0xff25774c
[4] DOMString::DOMString(0xfe7058bc, 0x59eb8, 0xff345568, 0xff35a5e8,
0xff13e7b8, 0x0), at 0xff257898
[5] DStringPool::getPooledString(0x5ac68, 0x59eb8, 0xc, 0x20, 0x0, 0x0),
at 0xff25c638
[6] DocumentImpl::createElement(0x65a90, 0x59eb8, 0x0, 0xff35a5e8,
0x64878, 0x0), at 0xff26797c
[7] DOM_Document::createElement(0xfe705a0c, 0xfe705cb8, 0x59eb8,
0xff35a5e8, 0xff25e560, 0x0), at 0xff259d00
[8] DOMParser::startElement(0xfe705ca0, 0x120aa8, 0x0, 0x0, 0xd5330, 0x0),
at 0xff255470
[9] XMLScanner::scanStartTag(0xff30efcc, 0xff2d30b4, 0x1, 0xcebec, 0x800,
0xb14), at 0xff295c80
[10] XMLScanner::scanContent(0x43, 0x0, 0xff30e310, 0x1, 0xceb40,
0xff30e360), at 0xff294208
[11] XMLScanner::scanDocument(0xceb38, 0xfe705c80, 0x0, 0xff35a5e8, 0x3ff,
0x0), at 0xff29266c
[12] DOMParser::parse(0xfe705ca0, 0xfe705c80, 0x0, 0x442b3, 0x0, 0x0), at
0xff2543a8
=>[13] worker(arg = (nil)), line 58 in "thrTest.cpp"
-------------------------------
In my case, in most cases the test failed when the number of threads were
above 10. Am I doing something wrong here or is there some bug in Xerces?
Thanks,
Jeetu
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]