diff -x log -x Makefile -x Makefile.in -ruN curl-7.10.6.orig/tests/data/Makefile.am curl-7.10.6/tests/data/Makefile.am
--- curl-7.10.6.orig/tests/data/Makefile.am	2003-07-28 10:19:30.000000000 +0200
+++ curl-7.10.6/tests/data/Makefile.am	2003-08-05 17:41:10.000000000 +0200
@@ -21,4 +21,4 @@
 test500 test501 test502 test503 test504 test136 test57 test137 test138 \
 test58 test139 test140 test141 test59 test60 test61 test142 test143 test62 \
 test63 test64 test65 test66 test144 test145 test67 test68 test41 \
-test40 test42 test69 test70 test71
+test40 test42 test69 test70 test71 test506
diff -x log -x Makefile -x Makefile.in -ruN curl-7.10.6.orig/tests/data/test506 curl-7.10.6/tests/data/test506
--- curl-7.10.6.orig/tests/data/test506	1970-01-01 01:00:00.000000000 +0100
+++ curl-7.10.6/tests/data/test506	2003-08-05 17:42:05.000000000 +0200
@@ -0,0 +1,99 @@
+# Server-side
+<reply>
+<data1>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Type: text/html
+Funny-head: yesyes
+Set-Cookie: test2=two; domain=host.foo.com; expires=Tue Feb 1 11:56:27 MET 2007
+Set-Cookie: test1=one; domain=foo.com; expires=Tue Feb 1 11:56:27 MET 2007
+Content-Length: 4
+
+boo
+</data1>
+<data2>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Type: text/html
+Funny-head: yesyes
+Set-Cookie: test3=tree; domain=foo.com; expires=Tue Feb 1 11:56:27 MET 2007
+Set-Cookie: test5=five; domain=host.foo.com; expires=Tue Feb 1 11:56:27 MET 2007
+Content-Length: 4
+
+foo
+</data2>
+<data3>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Type: text/html
+Funny-head: yesyes
+Set-Cookie: test4=four; domain=host.foo.com; expires=Tue Feb 1 11:56:27 MET 2007
+Content-Length: 4
+
+bar
+</data3>
+<data4>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Type: text/html
+Funny-head: yesyes
+Set-Cookie: test6=six; domain=host.foo.com; expires=Tue Feb 1 11:56:27 MET 2008
+Content-Length: 6
+
+xenon
+</data4>
+<data5>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Type: text/html
+Funny-head: yesyes
+Set-Cookie: test1=overwritten; domain=foo.com; expires=Tue Feb 2 11:56:27 MET 2007
+Content-Type: text/html
+Content-Length: 4
+
+nop
+</data5>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+<name>
+HTTP with thread safe cookie list using share interface
+</name>
+<tool>
+lib506.run
+</tool>
+<command>
+http://%HOSTIP:%HOSTPORT/506
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<stdout>
+bar
+boo
+foo
+nop
+xenon
+</stdout>
+<stderr>
+http://%HOSTIP:%HOSTPORT/506
+</stderr>
+<file name="log/jar506.sort">
+.foo.com	TRUE	/	FALSE	1170413787	test1	overwritten
+.host.foo.com	TRUE	/	FALSE	1170327387	test2	two
+.foo.com	TRUE	/	FALSE	1170327387	test3	tree
+.host.foo.com	TRUE	/	FALSE	1170327387	test4	four
+.host.foo.com	TRUE	/	FALSE	1170327387	test5	five
+.host.foo.com	TRUE	/	FALSE	1201863387	test6	six
+</file>
+</verify>
diff -x log -x Makefile -x Makefile.in -ruN curl-7.10.6.orig/tests/libtest/Makefile.am curl-7.10.6/tests/libtest/Makefile.am
--- curl-7.10.6.orig/tests/libtest/Makefile.am	2003-06-10 14:05:12.000000000 +0200
+++ curl-7.10.6/tests/libtest/Makefile.am	2003-08-05 17:44:06.000000000 +0200
@@ -8,10 +8,10 @@
 
 LIBDIR = ../../lib
 
-SUPPORTFILES = first.c test.h
+SUPPORTFILES = first.c test.h lib506.run
 
 # here are all tools used for running libcurl tests
-noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505
+noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505 lib506
 
 lib500_SOURCES = lib500.c $(SUPPORTFILES)
 lib500_LDADD = $(LIBDIR)/libcurl.la
@@ -36,3 +36,8 @@
 lib505_SOURCES = lib505.c $(SUPPORTFILES)
 lib505_LDADD = $(LIBDIR)/libcurl.la
 lib505_DEPENDENCIES = $(LIBDIR)/libcurl.la
+
+lib506_SOURCES = lib506.c $(SUPPORTFILES)
+lib506_LDADD = $(LIBDIR)/libcurl.la -lpthread
+lib506_DEPENDENCIES = $(LIBDIR)/libcurl.la
+
diff -x log -x Makefile -x Makefile.in -ruN curl-7.10.6.orig/tests/libtest/lib506.c curl-7.10.6/tests/libtest/lib506.c
--- curl-7.10.6.orig/tests/libtest/lib506.c	1970-01-01 01:00:00.000000000 +0100
+++ curl-7.10.6/tests/libtest/lib506.c	2003-08-05 19:24:32.000000000 +0200
@@ -0,0 +1,248 @@
+#include "test.h"
+#include <stdlib.h>
+#include <pthread.h>
+#include <ctype.h>
+#include <errno.h>
+
+#define REPEATS_INNER 10
+#define REPEATS_OUTER 5
+#define THREADS 4
+const char *HOSTHEADER = "Host: www.host.foo.com";
+const char *JAR = "log/jar506";
+#define BUFSIZE 4096
+#define RANDOMSLEEP
+
+/* struct containing data of a thread */
+struct Tdata {
+  CURLSH *share;
+  char *url;
+  pthread_t thread;
+};
+
+/* struct containing mutexes for the share */
+struct Mutexes {
+  pthread_mutex_t share;
+  pthread_mutex_t dnsCache;
+  pthread_mutex_t cookies;
+} mutexes;
+
+
+void mutexes_init(struct Mutexes *m) {
+    if (pthread_mutex_init(&m->share, NULL) )
+      abort();
+    if (pthread_mutex_init(&m->dnsCache, NULL) )
+      abort();
+    if (pthread_mutex_init(&m->cookies, NULL) )
+      abort();
+}
+
+
+void mutexes_destroy(struct Mutexes *m) {
+    if (pthread_mutex_destroy(&m->share) )
+      abort();
+    if (pthread_mutex_destroy(&m->dnsCache) )
+      abort();
+    if (pthread_mutex_destroy(&m->cookies) )
+      abort();
+}
+
+
+/* lock callback */
+void lock(CURL *handle, curl_lock_data data, curl_lock_access access, void *useptr ) {
+  pthread_mutex_t *mutex;
+  struct Mutexes *mutexes = (struct Mutexes *) useptr;
+
+  switch ( data ) {
+    case CURL_LOCK_DATA_SHARE:
+      mutex = &mutexes->share;
+      break;
+    case CURL_LOCK_DATA_DNS:
+      mutex = &mutexes->dnsCache;
+      break;
+    case CURL_LOCK_DATA_COOKIE:
+      mutex = &mutexes->cookies;
+      break;
+    default:
+      fprintf(stderr, "lock: no such data: %d\n",data);
+      return;
+  }
+
+  pthread_mutex_lock( mutex );
+}
+
+/* unlock callback */
+void unlock(CURL *handle, curl_lock_data data, void *useptr ) {
+  pthread_mutex_t *mutex;
+  struct Mutexes *mutexes = (struct Mutexes *) useptr;
+ 
+  switch ( data ) {
+    case CURL_LOCK_DATA_SHARE:
+      mutex = &mutexes->share;
+      break;
+    case CURL_LOCK_DATA_DNS:
+      mutex = &mutexes->dnsCache;
+      break;
+    case CURL_LOCK_DATA_COOKIE:
+      mutex = &mutexes->cookies;
+      break;
+    default:
+      fprintf(stderr, "unlock: no such data: %d\n",data);
+      return;
+  }
+ 
+  pthread_mutex_unlock( mutex );
+}
+
+
+/* build host entry */
+struct curl_slist *sethost(struct curl_slist *headers) {
+  return curl_slist_append(NULL, HOSTHEADER );
+}
+
+
+/* the thread function */
+void *fire(void *ptr) {
+  CURLcode code;
+  struct curl_slist *headers;
+  struct Tdata *tdata = (struct Tdata*)ptr;
+  CURL *curl = curl_easy_init();
+  struct timespec wts, rts;
+  int i;
+
+  headers = sethost(NULL);
+  curl_easy_setopt(curl, CURLOPT_HTTPHEADER,   (void*)headers);
+  curl_easy_setopt(curl, CURLOPT_URL,          (void*)tdata->url);
+  curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1);
+  curl_easy_setopt(curl, CURLOPT_SHARE, (void*)tdata->share);
+
+  for (i=0; i<REPEATS_INNER; i++) {
+  
+#ifdef RANDOMSLEEP
+    wts.tv_sec = 0;
+    wts.tv_nsec = random()%50000000;
+    while (wts.tv_nsec>0) {
+       rts.tv_nsec = 0;
+       nanosleep( &wts, &rts );
+       wts.tv_nsec = rts.tv_nsec;
+    }
+#endif
+  
+    code = curl_easy_perform(curl);
+    if( code != CURLE_OK ) {
+      fprintf(stderr, "perform url '%s' repeat %d failed, curlcode %ld\n", tdata->url, i, code);
+    }
+  }
+
+  curl_easy_cleanup(curl);
+  curl_slist_free_all(headers);
+
+  return NULL;
+}
+
+
+/* build request url */
+char *suburl(char *base, int i) {
+  int len = strlen(base);
+  char *url = (char *)malloc(len+5);
+  if (!url) {
+    abort();
+  }
+  strcpy(url, base);
+  strcat(url, "0000");
+  url[len+3] = 49+i;
+  return url;
+}
+
+
+/* test function */
+CURLcode test(char *URL)
+{
+  CURLcode res;
+  CURLSHcode scode;
+  char *url;
+  struct Tdata tdata[THREADS];
+  CURL *curl;
+  CURLSH *share;
+  struct curl_slist *headers;
+  int i,j;
+  int error;
+  FILE *pipe;
+  char inbuffer[BUFSIZE];
+  size_t read;
+
+#ifdef RANDOMSLEEP
+  srand((unsigned int)time(NULL));
+#endif
+  
+  curl_global_init(CURL_GLOBAL_ALL);
+
+  /* prepare share */
+  mutexes_init(&mutexes);
+  share = curl_share_init();
+  curl_share_setopt(share, CURLSHOPT_LOCKFUNC,   lock );
+  curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, unlock );
+  curl_share_setopt(share, CURLSHOPT_USERDATA,   &mutexes );
+  curl_share_setopt(share, CURLSHOPT_SHARE,      CURL_LOCK_DATA_COOKIE);
+  
+  res = 0;
+
+  for (j=0; j<REPEATS_OUTER; j++ ) {
+  
+    /* start treads */
+    for (i=0; i<THREADS; i++ ) {
+      
+      /* set thread data */
+      tdata[i].url   = suburl(URL,i);
+      tdata[i].share = share;
+
+      /* create thread */
+      error = pthread_create(&tdata[i].thread,
+                             NULL, /* default attributes please */
+                             fire,
+                             &tdata[i]);
+      if(0 != error) {
+        fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
+        res |= 1024;
+      }
+    }
+
+    /* finish thread   */
+    for (i=0; i<THREADS; i++ ) {
+      error = pthread_join(tdata[i].thread, NULL);
+      if(0 != error) {
+        fprintf(stderr, "Couldn't join thread number %d, errno %d\n", i, error);
+        res |= 2048;
+      }
+      free(tdata[i].url);
+    }
+
+  }
+
+  /* fetch a another one and save cookies */
+  curl = curl_easy_init();
+
+  url = suburl(URL, THREADS);
+  headers = sethost(NULL);
+  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, (void*)headers);
+  curl_easy_setopt(curl, CURLOPT_URL,        url);
+  curl_easy_setopt(curl, CURLOPT_SHARE,      share);
+  curl_easy_setopt(curl, CURLOPT_COOKIEJAR,  JAR);
+  curl_easy_perform(curl);
+
+  curl_easy_cleanup(curl);
+  curl_slist_free_all(headers);
+  free(url);
+  
+  
+  /* free share */
+  scode = curl_share_cleanup(share);
+  if (scode!=CURLSHE_OK)
+    fprintf(stderr, "CURL_LOCK_DATA_COOKIE failed, code errno %d\n", scode);
+  
+  mutexes_destroy(&mutexes);
+
+  curl_global_cleanup();
+ 
+  return res;
+}
+
diff -x log -x Makefile -x Makefile.in -ruN curl-7.10.6.orig/tests/libtest/lib506.run curl-7.10.6/tests/libtest/lib506.run
--- curl-7.10.6.orig/tests/libtest/lib506.run	1970-01-01 01:00:00.000000000 +0100
+++ curl-7.10.6/tests/libtest/lib506.run	2003-08-05 19:01:16.000000000 +0200
@@ -0,0 +1,6 @@
+#!/bin/sh
+TEST=506
+JAR="log/jar$TEST"
+libtest/lib$TEST $1|sort|uniq
+sed $JAR -e '1,/^$/d' 2>&1|sort -k 6 >$JAR.sort
+#rm $JAR

