--- include/libxml/parserInternals.h	2010-10-15 09:13:56.000000000 -0700
+++ include/libxml/parserInternals.h	2011-03-08 09:38:40.000000000 -0800
@@ -279,6 +279,12 @@
 XMLPUBVAR const xmlChar xmlStringText[];
 XMLPUBVAR const xmlChar xmlStringTextNoenc[];
 XMLPUBVAR const xmlChar xmlStringComment[];
+
+/*
+ * Initialize and Cleanup functions.  Only necessary if multithreaded.
+ */
+XMLPUBFUN void XMLCALL xmlInitParserInternals   (void);
+XMLPUBFUN void XMLCALL xmlCleanupParserInternals(void);
 
 /*
  * Function to finish the work of the macros where needed.
==== //depot/parser.c#1 - /home/llib/work/clients/llib-gws2/parser.c ====
# action=edit type=text
--- parser.c	2010-10-15 09:13:56.000000000 -0700
+++ parser.c	2011-03-01 15:48:37.000000000 -0800
@@ -14010,6 +14010,7 @@
 	    (xmlGenericError == NULL))
 	    initGenericErrorDefaultFunc(NULL);
 	xmlInitMemory();
+        xmlInitParserInternals();
 	xmlInitCharEncodingHandlers();
 	xmlDefaultSAXHandlerInit();
 	xmlRegisterDefaultInputCallbacks();
@@ -14070,6 +14071,7 @@
     xmlSchemaCleanupTypes();
     xmlRelaxNGCleanupTypes();
 #endif
+    xmlCleanupParserInternals();
     xmlCleanupGlobals();
     xmlResetLastError();
     xmlCleanupThreads(); /* must be last if called not from the main thread */
==== //depot/parserInternals.c#1 - /home/llib/work/clients/llib-gws2/parserInternals.c ====
# action=edit type=text
--- parserInternals.c	2010-10-15 09:13:56.000000000 -0700
+++ parserInternals.c	2011-03-08 10:31:13.000000000 -0800
@@ -54,6 +54,40 @@
 #endif
 #include "include/libxml/globals.h"
 #include "include/libxml/chvalid.h"
+
+/*
+ * Protects xmlInputId.
+ */
+static xmlMutexPtr xmlInputIdMutex = NULL;
+
+/*
+ * counter used for unique id in xmlNewInputStream.  Protected by
+ * xmlInputIdMutex.
+ */
+static int xmlInputId = 0;
+
+/**
+ * xmlInitParserInternals:
+ *
+ * Initialize globals used for multithreading in this file.
+ * e.g., xmlInputIdMutex.
+ */
+void xmlInitParserInternals(void) {
+    if (xmlInputIdMutex == NULL)
+        xmlInputIdMutex = xmlNewMutex();
+}
+
+/**
+ * xmlCleanupParserInternals:
+ *
+ * Cleanup globals used for multithreading in this file.  e.g., xmlInputIdMutex.
+ */
+void xmlCleanupParserInternals(void) {
+    if (xmlInputIdMutex != NULL) {
+        xmlFreeMutex(xmlInputIdMutex);
+        xmlInputIdMutex = NULL;
+    }
+}
 
 /*
  * Various global defaults for parsing
@@ -1378,7 +1412,6 @@
 xmlParserInputPtr
 xmlNewInputStream(xmlParserCtxtPtr ctxt) {
     xmlParserInputPtr input;
-    static int id = 0;
 
     input = (xmlParserInputPtr) xmlMalloc(sizeof(xmlParserInput));
     if (input == NULL) {
@@ -1389,11 +1422,9 @@
     input->line = 1;
     input->col = 1;
     input->standalone = -1;
-    /*
-     * we don't care about thread reentrancy unicity for a single
-     * parser context (and hence thread) is sufficient.
-     */
-    input->id = id++;
+    xmlMutexLock(xmlInputIdMutex);
+    input->id = xmlInputId++;
+    xmlMutexUnlock(xmlInputIdMutex);
     return(input);
 }
 
