Index: trunk/src/VBox/Main/include/ThreadTask.h
===================================================================
--- trunk/src/VBox/Main/include/ThreadTask.h	(revision 63181)
+++ trunk/src/VBox/Main/include/ThreadTask.h	(revision 63182)
@@ -39,5 +39,7 @@
     { };
 
-    HRESULT createThread(PRTTHREAD pThread = NULL, RTTHREADTYPE enmType = RTTHREADTYPE_MAIN_WORKER);
+    HRESULT createThread(void);
+    HRESULT createThreadWithType(RTTHREADTYPE enmType);
+    HRESULT createThreadWithRaceCondition(PRTTHREAD pThread);
 
     virtual void handler() = 0;
@@ -45,4 +47,5 @@
 
 protected:
+    HRESULT createThreadInternal(RTTHREADTYPE enmType, PRTTHREAD pThread);
     static DECLCALLBACK(int) taskHandlerThreadProc(RTTHREAD thread, void *pvUser);
 
Index: trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp	(revision 63181)
+++ trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp	(revision 63182)
@@ -660,5 +660,5 @@
             {
                 ComPtr<Progress> ptrProgress = pTask->ptrProgress;
-                hrc = pTask->createThread(NULL /*phThread*/, RTTHREADTYPE_DEFAULT);
+                hrc = pTask->createThreadWithType(RTTHREADTYPE_DEFAULT);
                 pTask = NULL; /* The _completely_ _undocumented_ createThread method always consumes pTask. */
                 if (SUCCEEDED(hrc))
@@ -2088,5 +2088,5 @@
         {
             ComPtr<Progress> ptrProgress = pTask->ptrProgress;
-            hrc = pTask->createThread(NULL, RTTHREADTYPE_DEFAULT);
+            hrc = pTask->createThreadWithType(RTTHREADTYPE_DEFAULT);
             pTask = NULL;               /* always consumed by createThread */
             if (SUCCEEDED(hrc))
Index: trunk/src/VBox/Main/src-all/ThreadTask.cpp
===================================================================
--- trunk/src/VBox/Main/src-all/ThreadTask.cpp	(revision 63181)
+++ trunk/src/VBox/Main/src-all/ThreadTask.cpp	(revision 63182)
@@ -20,4 +20,5 @@
 #include "ThreadTask.h"
 
+
 /**
  * Starts the task (on separate thread), consuming @a this.
@@ -28,32 +29,64 @@
  *
  * Possible way of usage:
+ * @code{.cpp}
+        HRESULT hr;
+        SomeTaskInheritedFromThreadTask *pTask = NULL;
+        try
+        {
+            pTask = new SomeTaskInheritedFromThreadTask(this);
+            if (!pTask->Init()) // some init procedure
+                throw E_FAIL;
+        }
+        catch (...)
+        {
+            if (pTask);
+                delete pTask;
+            return E_FAIL;
+        }
+        return pTask->createThread(); // pTask is always consumed
+   @endcode
  *
- * @code{.cpp}
- * int vrc = VINF_SUCCESS;
- * HRESULT hr = S_OK;
+ * @sa createThreadWithType, createThreadWithRaceCondition
+ */
+HRESULT ThreadTask::createThread(void)
+{
+    return createThreadInternal(RTTHREADTYPE_MAIN_WORKER, NULL /*pThread*/);
+}
+
+
+/**
+ * Same ThreadTask::createThread(), except it takes a thread type parameter.
  *
- * SomeTaskInheritedFromThreadTask* pTask = NULL;
- * try
- * {
- *     pTask = new SomeTaskInheritedFromThreadTask(this);
- *     if (!pTask->Init())//some init procedure
- *     {
- *         delete pTask;
- *         throw E_FAIL;
- *     }
- *     //this function delete pTask in case of exceptions, so
- *     there is no need the call of delete operator
+ * @param   enmType     The thread type.
+ */
+HRESULT ThreadTask::createThreadWithType(RTTHREADTYPE enmType)
+{
+    return createThreadInternal(enmType, NULL /*pThread*/);
+}
+
+
+/**
+ * Same ThreadTask::createThread(), except it returns a thread handle.
  *
- *     hr = pTask->createThread();
- * }
- * catch(...)
- * {
- *     vrc = E_FAIL;
- * }
- * @endcode
+ * If the task thread is incorrectly mananged, the caller may easily race the
+ * completion and termination of the task thread!  Use with care!
+ *
+ * @param   pThread     Handle of the worker thread.
  */
-HRESULT ThreadTask::createThread(PRTTHREAD pThread /*= NULL*/, RTTHREADTYPE enmType /*= RTTHREADTYPE_MAIN_WORKER*/)
+HRESULT ThreadTask::createThreadWithRaceCondition(PRTTHREAD pThread)
 {
-    m_pThread = pThread;
+    return createThreadInternal(RTTHREADTYPE_MAIN_WORKER, pThread);
+}
+
+
+/**
+ * Internal worker for ThreadTask::createThread,
+ * ThreadTask::createThreadWithType, ThreadTask::createThreadwithRaceCondition.
+ *
+ * @note Always consumes @a this!
+ */
+HRESULT ThreadTask::createThreadInternal(RTTHREADTYPE enmType, PRTTHREAD pThread)
+{
+    m_pThread = pThread; /** @todo this is utter non-sense! */
     int vrc = RTThreadCreate(m_pThread,
                              taskHandlerThreadProc,
@@ -69,4 +102,5 @@
     return E_FAIL;
 }
+
 
 /**
Index: trunk/src/VBox/Main/src-client/GuestCtrlImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/GuestCtrlImpl.cpp	(revision 63181)
+++ trunk/src/VBox/Main/src-client/GuestCtrlImpl.cpp	(revision 63182)
@@ -584,5 +584,5 @@
                 }
 
-                hr = pTask->createThread(NULL, RTTHREADTYPE_MAIN_HEAVY_WORKER);
+                hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER);
 
                 if (SUCCEEDED(hr))
Index: trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp	(revision 63181)
+++ trunk/src/VBox/Main/src-client/GuestDnDSourceImpl.cpp	(revision 63182)
@@ -383,5 +383,5 @@
 /** @todo r=bird: The code using hThreadRcv is racing the thread termination. Since the thread isn't
  * created waitable, the handle goes away if we it terminates before our RTThreadUserWait call returns. */
-        hr = pTask->createThread(&hThreadRcv);
+        hr = pTask->createThreadWithRaceCondition(&hThreadRcv);
 
     }
Index: trunk/src/VBox/Main/src-client/GuestDnDTargetImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/GuestDnDTargetImpl.cpp	(revision 63181)
+++ trunk/src/VBox/Main/src-client/GuestDnDTargetImpl.cpp	(revision 63182)
@@ -655,5 +655,5 @@
 /** @todo r=bird: The code using hThreadSend is racing the thread termination. Since the thread isn't
  * created waitable, the handle goes away if we it terminates before our RTThreadUserWait call returns. */
-        hr = pTask->createThread(&rcThreadSend);
+        hr = pTask->createThreadWithRaceCondition(&rcThreadSend);
 
     }
Index: trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp	(revision 63181)
+++ trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp	(revision 63182)
@@ -2512,5 +2512,5 @@
         }
 
-        hr = pTask->createThread(NULL, RTTHREADTYPE_MAIN_HEAVY_WORKER);
+        hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER);
 
         if (SUCCEEDED(hr))
@@ -2585,5 +2585,5 @@
         }
 
-        hr = pTask->createThread(NULL, RTTHREADTYPE_MAIN_HEAVY_WORKER);
+        hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER);
 
         if (SUCCEEDED(hr))
Index: trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp	(revision 63181)
+++ trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp	(revision 63182)
@@ -1064,5 +1064,5 @@
                 }
 
-                hr = pTask->createThread(NULL, RTTHREADTYPE_MAIN_HEAVY_WORKER);
+                hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER);
 
                 if (SUCCEEDED(hr))
Index: trunk/src/VBox/Main/src-server/VFSExplorerImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/VFSExplorerImpl.cpp	(revision 63181)
+++ trunk/src/VBox/Main/src-server/VFSExplorerImpl.cpp	(revision 63182)
@@ -413,5 +413,5 @@
 
         //this function delete task in case of exceptions, so there is no need in the call of delete operator
-        rc = pTask->createThread(NULL, RTTHREADTYPE_MAIN_HEAVY_WORKER);
+        rc = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER);
     }
     catch (HRESULT aRC)
@@ -531,5 +531,5 @@
 
         //this function delete task in case of exceptions, so there is no need in the call of delete operator
-        rc = pTask->createThread(NULL, RTTHREADTYPE_MAIN_HEAVY_WORKER);
+        rc = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER);
     }
     catch (HRESULT aRC)
Index: trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp	(revision 63181)
+++ trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp	(revision 63182)
@@ -2567,5 +2567,5 @@
 
         //this function delete pTask in case of exceptions, so there is no need in the call of delete operator
-        hr = pTask->createThread(NULL, RTTHREADTYPE_MAIN_WORKER);
+        hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_WORKER);
 
     }
