Index: pthreads/PThreadPrivateData.h
===================================================================
--- pthreads/PThreadPrivateData.h	(revision 7480)
+++ pthreads/PThreadPrivateData.h	(working copy)
@@ -56,6 +56,8 @@
 
     volatile bool idSet;
 
+    volatile bool isDetached;
+
     volatile Thread::ThreadPriority threadPriority;
     
     volatile Thread::ThreadPolicy threadPolicy;
Index: pthreads/PThread.c++
===================================================================
--- pthreads/PThread.c++	(revision 7480)
+++ pthreads/PThread.c++	(working copy)
@@ -29,6 +29,8 @@
 #include <sys/unistd.h>
 #endif
 
+#include <errno.h>
+
 #if defined (__linux__)
     #include <sched.h>
 #endif
@@ -378,6 +380,7 @@
     pd->stackSize = 0;
     pd->stackSizeLocked = false;
     pd->idSet = false;
+    pd->isDetached = false;
     pd->isRunning = false;
     pd->isCanceled = false;
     pd->uniqueId = pd->nextId;
@@ -410,6 +413,7 @@
 	cancel();
     }
 
+    detach();
     delete pd;
     
     _prvData = 0;
@@ -668,8 +672,12 @@
 int Thread::detach() {
 
     PThreadPrivateData *pd = static_cast<PThreadPrivateData *> (_prvData);
-    return pthread_detach(pd->tid);
 
+    if (!pd->idSet) return ESRCH;
+    if (pd->isDetached) return EINVAL;
+    int err = pthread_detach(pd->tid);
+    if (!err) { pd->isDetached = true; }
+    return err;
 }
 
 //-----------------------------------------------------------------------------
@@ -682,8 +690,12 @@
 
     void *threadResult = 0; // Dummy var.
     PThreadPrivateData *pd = static_cast<PThreadPrivateData *> (_prvData);
-    return pthread_join(pd->tid, &threadResult);
 
+    if (!pd->idSet) return ESRCH;
+    if (pd->isDetached) return EINVAL;
+    int err = pthread_join(pd->tid, &threadResult);
+    if (!err) { pd->isDetached = true; }
+    return err;
 }
 
 //-----------------------------------------------------------------------------
