Index: /pjproject/trunk/pjlib/src/pjlib-test/ioq_perf.c
===================================================================
--- /pjproject/trunk/pjlib/src/pjlib-test/ioq_perf.c	(revision 350)
+++ /pjproject/trunk/pjlib/src/pjlib-test/ioq_perf.c	(revision 351)
@@ -85,10 +85,10 @@
         if (bytes_read < 0) {
             pj_status_t rc = -bytes_read;
-            char errmsg[128];
+            char errmsg[PJ_ERR_MSG_SIZE];
 
 	    if (rc != last_error) {
 	        //last_error = rc;
 	        pj_strerror(rc, errmsg, sizeof(errmsg));
-	        PJ_LOG(3,(THIS_FILE, "...error: read error, bytes_read=%d (%s)", 
+	        PJ_LOG(3,(THIS_FILE,"...error: read error, bytes_read=%d (%s)", 
 		          bytes_read, errmsg));
 	        PJ_LOG(3,(THIS_FILE, 
@@ -179,17 +179,31 @@
 }
 
+struct thread_arg
+{
+    int		  id;
+    pj_ioqueue_t *ioqueue;
+    unsigned	  counter;
+};
+
 /* The worker thread. */
-static int worker_thread(void *arg)
-{
-    pj_ioqueue_t *ioqueue = arg;
+static int worker_thread(void *p)
+{
+    struct thread_arg *arg = p;
     const pj_time_val timeout = {0, 100};
     int rc;
 
     while (!thread_quit_flag) {
-        rc = pj_ioqueue_poll(ioqueue, &timeout);
+
+	++arg->counter;
+        rc = pj_ioqueue_poll(arg->ioqueue, &timeout);
 	//TRACE_((THIS_FILE, "     thread: poll returned rc=%d", rc));
         if (rc < 0) {
-            app_perror("...error in pj_ioqueue_poll()", pj_get_netos_error());
-            return -1;
+	    char errmsg[PJ_ERR_MSG_SIZE];
+	    pj_strerror(-rc, errmsg, sizeof(errmsg));
+            PJ_LOG(3, (THIS_FILE, 
+		       "...error in pj_ioqueue_poll() in thread %d "
+		       "after %d loop: %s [pj_status_t=%d]", 
+		       arg->id, arg->counter, errmsg, -rc));
+            //return -1;
         }
     }
@@ -316,7 +330,14 @@
     /* Create the threads. */
     for (i=0; i<thread_cnt; ++i) {
+	struct thread_arg *arg;
+
+	arg = pj_pool_zalloc(pool, sizeof(*arg));
+	arg->id = i;
+	arg->ioqueue = ioqueue;
+	arg->counter = 0;
+
         rc = pj_thread_create( pool, NULL, 
                                &worker_thread, 
-                               ioqueue, 
+                               arg, 
                                PJ_THREAD_DEFAULT_STACK_SIZE, 
                                PJ_THREAD_SUSPENDED, &thread[i] );
@@ -383,4 +404,9 @@
     }
 
+    /* Destroy threads */
+    for (i=0; i<thread_cnt; ++i) {
+        pj_thread_destroy(thread[i]);
+    }
+
     /* Destroy ioqueue. */
     TRACE_((THIS_FILE, "     destroying ioqueue.."));
@@ -403,7 +429,6 @@
     *p_bandwidth = (pj_uint32_t)bandwidth;
 
-    PJ_LOG(3,(THIS_FILE, "   %.4s    %d         %d        %3d us  %8d KB/s",
+    PJ_LOG(3,(THIS_FILE, "   %.4s    %d         %d        %8d KB/s",
               type_name, thread_cnt, sockpair_cnt,
-              -1 /*total_elapsed_usec/sockpair_cnt*/,
               *p_bandwidth));
 
@@ -441,4 +466,5 @@
         { PJ_SOCK_DGRAM, "udp", 4, 4},
         { PJ_SOCK_DGRAM, "udp", 4, 8},
+        { PJ_SOCK_DGRAM, "udp", 4, 16},
         { PJ_SOCK_STREAM, "tcp", 1, 1},
         { PJ_SOCK_STREAM, "tcp", 1, 2},
@@ -453,4 +479,23 @@
         { PJ_SOCK_STREAM, "tcp", 4, 4},
         { PJ_SOCK_STREAM, "tcp", 4, 8},
+        { PJ_SOCK_STREAM, "tcp", 4, 16},
+/*
+	{ PJ_SOCK_DGRAM, "udp", 32, 1},
+	{ PJ_SOCK_DGRAM, "udp", 32, 1},
+	{ PJ_SOCK_DGRAM, "udp", 32, 1},
+	{ PJ_SOCK_DGRAM, "udp", 32, 1},
+	{ PJ_SOCK_DGRAM, "udp", 1, 32},
+	{ PJ_SOCK_DGRAM, "udp", 1, 32},
+	{ PJ_SOCK_DGRAM, "udp", 1, 32},
+	{ PJ_SOCK_DGRAM, "udp", 1, 32},
+	{ PJ_SOCK_STREAM, "tcp", 32, 1},
+	{ PJ_SOCK_STREAM, "tcp", 32, 1},
+	{ PJ_SOCK_STREAM, "tcp", 32, 1},
+	{ PJ_SOCK_STREAM, "tcp", 32, 1},
+	{ PJ_SOCK_STREAM, "tcp", 1, 32},
+	{ PJ_SOCK_STREAM, "tcp", 1, 32},
+	{ PJ_SOCK_STREAM, "tcp", 1, 32},
+	{ PJ_SOCK_STREAM, "tcp", 1, 32},
+*/
     };
     pj_size_t best_bandwidth;
@@ -458,7 +503,7 @@
 
     PJ_LOG(3,(THIS_FILE, "   Benchmarking %s ioqueue:", pj_ioqueue_name()));
-    PJ_LOG(3,(THIS_FILE, "   ==============================================="));
-    PJ_LOG(3,(THIS_FILE, "   Type  Threads  Skt.Pairs  Avg.Time    Bandwidth"));
-    PJ_LOG(3,(THIS_FILE, "   ==============================================="));
+    PJ_LOG(3,(THIS_FILE, "   ======================================="));
+    PJ_LOG(3,(THIS_FILE, "   Type  Threads  Skt.Pairs      Bandwidth"));
+    PJ_LOG(3,(THIS_FILE, "   ======================================="));
 
     best_bandwidth = 0;
@@ -478,5 +523,7 @@
             best_bandwidth = bandwidth, best_index = i;
 
-        /* Give it a rest before next test. */
+        /* Give it a rest before next test, to allow system to close the
+	 * sockets properly. 
+	 */
         pj_thread_sleep(500);
     }
Index: /pjproject/trunk/pjlib/src/pjlib-test/thread.c
===================================================================
--- /pjproject/trunk/pjlib/src/pjlib-test/thread.c	(revision 350)
+++ /pjproject/trunk/pjlib/src/pjlib-test/thread.c	(revision 351)
@@ -126,5 +126,14 @@
     }
 
+    pj_thread_sleep(500);
+
     if (flags & PJ_THREAD_SUSPENDED) {
+
+	/* Check that counter is still zero */
+	if (counter != 0) {
+	    PJ_LOG(3,(THIS_FILE, "...error: thread is not suspended"));
+	    return -1015;
+	}
+	
 	rc = pj_thread_resume(thread);
 	if (rc != PJ_SUCCESS) {
@@ -136,4 +145,6 @@
     PJ_LOG(3,(THIS_FILE, "..waiting for thread to quit.."));
 
+    pj_thread_sleep(500);
+
     quit_flag = 1;
     pj_thread_join(thread);
@@ -141,4 +152,9 @@
     pj_pool_release(pool);
 
+    if (counter == 0) {
+	PJ_LOG(3,(THIS_FILE, "...error: thread is not running"));
+	return -1025;
+    }
+    
     PJ_LOG(3,(THIS_FILE, "...%s success", title));
     return PJ_SUCCESS;
