--- glib-2.0.6-vanilla/glib/gstring.c	Wed Feb 20 22:33:16 2002
+++ glib-2.0.6/glib/gstring.c	Sat Jul  5 18:41:58 2003
@@ -52,7 +52,8 @@
 };
 
 G_LOCK_DEFINE_STATIC (string_mem_chunk);
-static GMemChunk *string_mem_chunk = NULL;
+static GMemChunk *global_string_mem_chunk = NULL;
+static GPrivate *thread_specific_string_mem_chunk = NULL;
 
 /* Hash Functions.
  */
@@ -210,15 +211,35 @@
 g_string_sized_new (gsize dfl_size)    
 {
   GString *string;
+  GMemChunk *string_mem_chunk;
 
-  G_LOCK (string_mem_chunk);
-  if (!string_mem_chunk)
-    string_mem_chunk = g_mem_chunk_new ("string mem chunk",
-					sizeof (GString),
-					1024, G_ALLOC_AND_FREE);
+  if (g_thread_supported())
+    {
+      G_LOCK (string_mem_chunk);
+      if (!thread_specific_string_mem_chunk)
+        {
+          thread_specific_string_mem_chunk = g_private_new((GDestroyNotify) g_mem_chunk_destroy);
+        }
+      G_UNLOCK (string_mem_chunk);
+      string_mem_chunk = g_private_get(thread_specific_string_mem_chunk);
+      if (!string_mem_chunk)
+        {
+          string_mem_chunk = g_mem_chunk_new ("string mem chunk",
+			                      sizeof (GString),
+				              1024, G_ALLOC_AND_FREE);
+          g_private_set(thread_specific_string_mem_chunk, string_mem_chunk);
+        }
+    }
+  else
+    {
+      if (!global_string_mem_chunk)
+        global_string_mem_chunk = g_mem_chunk_new ("string mem chunk",
+			                           sizeof (GString),
+				                   1024, G_ALLOC_AND_FREE);
+      string_mem_chunk = global_string_mem_chunk;
+    }
 
   string = g_chunk_new (GString, string_mem_chunk);
-  G_UNLOCK (string_mem_chunk);
 
   string->allocated_len = 0;
   string->len   = 0;
@@ -267,6 +288,7 @@
 	       gboolean free_segment)
 {
   gchar *segment;
+  GMemChunk *string_mem_chunk;
 
   g_return_val_if_fail (string != NULL, NULL);
 
@@ -278,9 +300,11 @@
   else
     segment = string->str;
 
-  G_LOCK (string_mem_chunk);
+  if (g_thread_supported())
+    string_mem_chunk = g_private_get(thread_specific_string_mem_chunk);
+  else
+    string_mem_chunk = global_string_mem_chunk;
   g_mem_chunk_free (string_mem_chunk, string);
-  G_UNLOCK (string_mem_chunk);
 
   return segment;
 }
