diff -urN stunnel-4.39-0008/src/ctx.c stunnel-4.39-0009/src/ctx.c
--- stunnel-4.39-0008/src/ctx.c	2011-07-21 12:07:10.483267955 +0200
+++ stunnel-4.39-0009/src/ctx.c	2011-07-21 12:07:57.753337279 +0200
@@ -37,6 +37,7 @@
 
 #include "common.h"
 #include "prototypes.h"
+#include "shctx.h"
 
 #ifndef OPENSSL_NO_RSA
 /* cache temporary keys up to 4096 bits */
@@ -170,6 +171,9 @@
         SSL_CTX_sess_set_get_cb(section->ctx, sess_get_cb);
         SSL_CTX_sess_set_remove_cb(section->ctx, sess_remove_cb);
     }
+    else if (global_options.nbproc > 1 ) {
+        shared_context_init(section->ctx, global_options.cachesize);
+    }
 
     /* info callback */
     SSL_CTX_set_info_callback(section->ctx, info_callback);
diff -urN stunnel-4.39-0008/src/Makefile.in stunnel-4.39-0009/src/Makefile.in
--- stunnel-4.39-0008/src/Makefile.in	2011-07-21 12:07:10.483267955 +0200
+++ stunnel-4.39-0009/src/Makefile.in	2011-07-21 12:16:28.424086295 +0200
@@ -90,7 +90,7 @@
 	log.$(OBJEXT) options.$(OBJEXT) protocol.$(OBJEXT) \
 	network.$(OBJEXT) resolver.$(OBJEXT) ssl.$(OBJEXT) \
 	ctx.$(OBJEXT) verify.$(OBJEXT) sthreads.$(OBJEXT) \
-	stunnel.$(OBJEXT)
+	stunnel.$(OBJEXT) shctx.$(OBJEXT) ebmbtree.$(OBJEXT) ebtree.$(OBJEXT)
 am__objects_4 = pty.$(OBJEXT) libwrap.$(OBJEXT)
 am_stunnel_OBJECTS = $(am__objects_2) $(am__objects_3) \
 	$(am__objects_4)
@@ -238,7 +238,7 @@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 common_headers = common.h prototypes.h version.h
-common_sources = str.c file.c client.c log.c options.c protocol.c network.c resolver.c ssl.c ctx.c verify.c sthreads.c stunnel.c
+common_sources = str.c file.c client.c log.c options.c protocol.c network.c resolver.c ssl.c ctx.c verify.c sthreads.c stunnel.c shctx.c ebmbtree.c ebtree.c
 unix_sources = pty.c libwrap.c
 shared_sources = env.c
 win32_sources = gui.c resources.h resources.rc stunnel.ico
diff -urN stunnel-4.39-0008/src/options.c stunnel-4.39-0009/src/options.c
--- stunnel-4.39-0008/src/options.c	2011-07-21 12:07:10.483267955 +0200
+++ stunnel-4.39-0009/src/options.c	2011-07-21 12:07:57.753337297 +0200
@@ -111,6 +111,37 @@
         break;
     }
 #endif /* HAVE_CHROOT */
+    switch(cmd) {
+    case CMD_INIT:
+        new_global_options.nbproc=1;
+        break;
+    case CMD_EXEC:
+        if(strcasecmp(opt, "nbproc"))
+            break;
+        new_global_options.nbproc=atoi(arg);
+        return NULL; /* OK */
+    case CMD_DEFAULT:
+        break;
+    case CMD_HELP:
+        s_log(LOG_NOTICE, "%-15s = number of listening process", "nbproc");
+        break;
+    }
+
+    switch(cmd) {
+    case CMD_INIT:
+        new_global_options.cachesize = max_clients ? max_clients*2 : SOMAXCONN*2;
+        break;
+    case CMD_EXEC:
+        if(strcasecmp(opt, "cachesize"))
+            break;
+        new_global_options.cachesize=atoi(arg);
+        return NULL; /* OK */
+    case CMD_DEFAULT:
+        break;
+    case CMD_HELP:
+        s_log(LOG_NOTICE, "%-15s = size of shared memory cache", "cachesize");
+        break;
+    }
 
     /* compression */
     switch(cmd) {
diff -urN stunnel-4.39-0008/src/prototypes.h stunnel-4.39-0009/src/prototypes.h
--- stunnel-4.39-0008/src/prototypes.h	2011-07-21 12:07:10.483267955 +0200
+++ stunnel-4.39-0009/src/prototypes.h	2011-07-21 12:07:57.753337297 +0200
@@ -79,6 +79,8 @@
 #ifdef HAVE_CHROOT
     char *chroot_dir;
 #endif
+    int nbproc;
+    int cachesize;
     unsigned long dpid;
     char *pidfile;
     int uid, gid;
diff -urN stunnel-4.39-0008/src/stunnel.c stunnel-4.39-0009/src/stunnel.c
--- stunnel-4.39-0008/src/stunnel.c	2011-07-21 12:07:10.483267955 +0200
+++ stunnel-4.39-0009/src/stunnel.c	2011-07-21 12:10:49.843589687 +0200
@@ -34,6 +34,7 @@
  *   also makes it possible to release a modified version which carries
  *   forward this exception.
  */
+int curproc = 1;
 
 #include "common.h"
 #include "prototypes.h"
@@ -79,7 +80,6 @@
 
 void main_initialize(char *arg1, char *arg2) {
     ssl_init(); /* initialize SSL library */
-    sthreads_init(); /* initialize critical sections & SSL callbacks */
     get_limits(); /* required by setup_fd() */
     parse_commandline(arg1, arg2);
 
@@ -130,7 +130,9 @@
          * or it won't be possible to remove the file on exit */
         /* create_pid() must be called after daemonize()
          * since the final pid is not known beforehand */
-        create_pid();
+
+        if ( curproc == 1 )
+           create_pid();
     }
 #endif /* standard Unix */
 }
@@ -376,17 +378,11 @@
 }
 
 static void daemonize(void) { /* go to background */
+    int i;
+
     close(0);
     close(1);
     close(2);
-#if defined(HAVE_DAEMON) && !defined(__BEOS__)
-    /* set noclose option when calling daemon() function,
-     * so it does not require /dev/null device in the chrooted directory */
-    if(daemon(0, 1)==-1) {
-        ioerror("daemon");
-        die(1);
-    }
-#else
     chdir("/");
     switch(fork()) {
     case -1:    /* fork failed */
@@ -397,10 +393,23 @@
     default:    /* parent */
         die(0);
     }
-#endif
 #ifdef HAVE_SETSID
     setsid(); /* ignore the error */
 #endif
+   for ( i = 2 ; i <= global_options.nbproc ; i++ ) {
+      switch(fork()) {
+      case -1:
+         ioerror("fork");
+         die(1);
+      case 0:
+         break;
+      default:
+         continue;
+      }
+      curproc = i;
+      break;
+   }	
+   sthreads_init(); /* initialize critical sections & SSL callbacks */
 }
 
 static void create_pid(void) {
