- include/libxml/globals.h include/libxml/threads.h threads.c
  testThreads.c: far more testing, cleaning up bugs
- *.c : make sure globals.h is always included.
Daniel
diff --git a/testThreads.c b/testThreads.c
index e0c06fb..044c90e 100644
--- a/testThreads.c
+++ b/testThreads.c
@@ -1,4 +1,5 @@
 #include <stdlib.h>
+#include <stdio.h>
 #include <features.h>
 #include <libxml/xmlversion.h>
 
@@ -26,13 +27,24 @@
     "test/threads/invalid.xml",
 };
 
+const char *Okay = "OK";
+const char *Failed = "Failed";
+
+#ifndef xmlDoValidityCheckingDefaultValue
+#error xmlDoValidityCheckingDefaultValue is not a macro
+#endif
+#ifndef xmlGenericErrorContext
+#error xmlGenericErrorContext is not a macro
+#endif
+
 static void *
 thread_specific_data(void *private_data)
 {
     xmlDocPtr myDoc;
     const char *filename = (const char *) private_data;
+    int okay = 1;
 
-    if (!strcmp(filename, "test/thread/invalid.xml") == 0) {
+    if (!strcmp(filename, "test/threads/invalid.xml")) {
         xmlDoValidityCheckingDefaultValue = 0;
         xmlGenericErrorContext = stdout;
     } else {
@@ -42,36 +54,72 @@
     myDoc = xmlParseFile(filename);
     if (myDoc) {
         xmlFreeDoc(myDoc);
-    } else
-        printf("parse failed\n");
-    if (!strcmp(filename, "test/thread/invalid.xml") == 0) {
-        if (xmlDoValidityCheckingDefaultValue != 0)
-	    printf("ValidityCheckingDefaultValue override failed\n");
-        if (xmlGenericErrorContext != stdout)
-	    printf("ValidityCheckingDefaultValue override failed\n");
     } else {
-        if (xmlDoValidityCheckingDefaultValue != 1)
-	    printf("ValidityCheckingDefaultValue override failed\n");
-        if (xmlGenericErrorContext != stderr)
-	    printf("ValidityCheckingDefaultValue override failed\n");
+        printf("parse failed\n");
+	okay = 0;
     }
-    return (NULL);
+    if (!strcmp(filename, "test/threads/invalid.xml")) {
+        if (xmlDoValidityCheckingDefaultValue != 0) {
+	    printf("ValidityCheckingDefaultValue override failed\n");
+	    okay = 0;
+	}
+        if (xmlGenericErrorContext != stdout) {
+	    printf("xmlGenericErrorContext override failed\n");
+	    okay = 0;
+	}
+    } else {
+        if (xmlDoValidityCheckingDefaultValue != 1) {
+	    printf("ValidityCheckingDefaultValue override failed\n");
+	    okay = 0;
+	}
+        if (xmlGenericErrorContext != stderr) {
+	    printf("xmlGenericErrorContext override failed\n");
+	    okay = 0;
+	}
+    }
+    if (okay == 0)
+	return((void *) Failed);
+    return ((void *) Okay);
 }
 
 int
 main()
 {
-    unsigned int i;
+    unsigned int i, repeat;
     unsigned int num_threads = sizeof(testfiles) / sizeof(testfiles[0]);
+    void *results[MAX_ARGC];
+    int ret;
 
     xmlInitParser();
-    xmlLoadCatalog(catalog);
+    for (repeat = 0;repeat < 10000;repeat++) {
+	xmlLoadCatalog(catalog);
 
-    for (i = 0; i < num_threads; i++)
-        pthread_create(&tid[i], 0, thread_specific_data, (void *) testfiles[i]);
-    for (i = 0; i < num_threads; i++)
-        pthread_join(tid[i], NULL);
+	for (i = 0; i < num_threads; i++) {
+	    results[i] = NULL;
+	    tid[i] = -1;
+	}
 
+	for (i = 0; i < num_threads; i++) {
+	    ret = pthread_create(&tid[i], 0, thread_specific_data,
+				 (void *) testfiles[i]);
+	    if (ret != 0) {
+		perror("pthread_create");
+		exit(1);
+	    }
+	}
+	for (i = 0; i < num_threads; i++) {
+	    ret = pthread_join(tid[i], &results[i]);
+	    if (ret != 0) {
+		perror("pthread_join");
+		exit(1);
+	    }
+	}
+
+	xmlCatalogCleanup();
+	for (i = 0; i < num_threads; i++)
+	    if (results[i] != (void *) Okay)
+		printf("Thread %d handling %s failed\n", i, testfiles[i]);
+    }
     xmlCleanupParser();
     xmlMemoryDump();
     return (0);