--- ./lib/Thread.cpp	2003/01/22 12:37:16	1.1
+++ ./lib/Thread.cpp	2003/01/22 16:11:00
@@ -150,10 +150,19 @@
         // exit thread
 #if   defined( HAVE_POSIX_THREAD )
 
+	// since we have our own portable and tricky "join"
+	// mechanism based on sNum, i.e., since NO ONE will ever
+	// call Thread::Join() to get our NULL result, we MUST
+	// detach before exiting [Marc Herbert]
+	pthread_detach (oldTID);
+
         // use exit()   if called from within this thread
         // use cancel() if called from a different thread
         if ( EqualID( pthread_self(), oldTID ) ) {
-            pthread_exit( NULL );
+            pthread_exit( NULL ); // returning a result if no one
+				  // joins to read it is useless! Just
+				  // finishing the thread execution
+				  // would be enough (and safer)
         } else {
             // Cray J90 doesn't have pthread_cancel; Iperf works okay without
 #ifdef HAVE_PTHREAD_CANCEL
@@ -197,20 +206,33 @@
     // run (pure virtual function)
     objectPtr->Run();
 
+#if 0
     // set TID to zero, then delete it
     // the zero TID causes Stop() in the destructor not to do anything
+
+    // This was an old workaround for the previously undiscovered
+    // "inheritance ordering" bug (see Server.hpp), that formerly
+    // prevented us to call pthread_exit() because of a stale socket
+    // problem.  Now that the bug is found (and the order corrected in
+    // Server.[ch]pp), we do not need this workaround anymore and may
+    // call pthread_exit() again. So we do NOT set mTID to zero
+    // anymore [Marc Herbert]
+
     objectPtr->mTID = ZeroID();
+#endif
 
     if ( objectPtr->mDeleteSelf ) {
         DELETE_PTR( objectPtr );
     }
 
+#if 0 // see above
     // decrement thread count and send condition signal
     // do this after the object is destroyed, otherwise NT complains
     sNum_cond.Lock();
     sNum--;
     sNum_cond.Signal();
     sNum_cond.Unlock();
+#endif
 
     return NULL;
 } // end run_wrapper
--- ./src/Server.cpp	2003/01/22 12:37:41	1.1
+++ ./src/Server.cpp	2003/01/22 15:49:55
@@ -63,8 +63,7 @@
  * ------------------------------------------------------------------- */
 
 Server::Server( short inPort, bool inUDP, int inSock )
-: PerfSocket( inPort, inUDP ),
-Thread() {
+: Thread(), PerfSocket( inPort, inUDP )  {
     mSock = inSock;
 }
 
--- ./src/Server.hpp	2003/01/22 12:37:41	1.1
+++ ./src/Server.hpp	2003/01/22 16:11:46
@@ -60,7 +60,10 @@
 #include "Thread.hpp"
 
 /* ------------------------------------------------------------------- */
-class Server : public PerfSocket, public Thread {
+class Server : public Thread, public PerfSocket {
+ // the inheritance order above is important: at destruction time, we
+ // must delete the socket BEFORE calling pthread_exit(), else
+ // Socket::~Socket() will never be called [Marc Herbert]
 public:
     // stores server socket, port and TCP/UDP mode
     Server( short inPort, bool inUDP, int inSock );
