VirtualBox

Changeset 64975 in vbox


Ignore:
Timestamp:
Dec 21, 2016 12:24:25 PM (8 years ago)
Author:
vboxsync
Message:

Main: fixed a race and removed the (now) superfluous ThreadTask::createThreadWithRaceCondition() method. Under no circumstances we must use the thread handle after the thread creation call succeeded -- because the thread could have terminated in the meantime.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ThreadTask.h

    r64973 r64975  
    3636    ThreadTask(const Utf8Str &t)
    3737        : m_strTaskName(t)
    38         , mAsync(false)
     38        , mAsync(true)
    3939    { }
    4040
     
    4444    HRESULT createThread(void);
    4545    HRESULT createThreadWithType(RTTHREADTYPE enmType);
    46     HRESULT createThreadWithRaceCondition(PRTTHREAD pThread);
    4746
    4847    inline Utf8Str getTaskName() const { return m_strTaskName; }
     
    5049
    5150protected:
    52     HRESULT createThreadInternal(RTTHREADTYPE enmType, PRTTHREAD pThread);
     51    HRESULT createThreadInternal(RTTHREADTYPE enmType);
    5352    static DECLCALLBACK(int) taskHandlerThreadProc(RTTHREAD thread, void *pvUser);
    5453
  • trunk/src/VBox/Main/src-all/ThreadTask.cpp

    r64972 r64975  
    4747   @endcode
    4848 *
    49  * @sa createThreadWithType, createThreadWithRaceCondition
     49 * @sa createThreadWithType
    5050 */
    5151HRESULT ThreadTask::createThread(void)
    5252{
    53     return createThreadInternal(RTTHREADTYPE_MAIN_WORKER, NULL /*phThread*/);
     53    return createThreadInternal(RTTHREADTYPE_MAIN_WORKER);
    5454}
    5555
     
    6262HRESULT ThreadTask::createThreadWithType(RTTHREADTYPE enmType)
    6363{
    64     return createThreadInternal(enmType, NULL /*phThread*/);
    65 }
    66 
    67 
    68 /**
    69  * Same ThreadTask::createThread(), except it returns a thread handle.
    70  *
    71  * If the task thread is incorrectly mananged, the caller may easily race the
    72  * completion and termination of the task thread!  Use with care!
    73  *
    74  * @param   phThread    Handle of the worker thread.
    75  */
    76 HRESULT ThreadTask::createThreadWithRaceCondition(PRTTHREAD phThread)
    77 {
    78     return createThreadInternal(RTTHREADTYPE_MAIN_WORKER, phThread);
     64    return createThreadInternal(enmType);
    7965}
    8066
     
    8268/**
    8369 * Internal worker for ThreadTask::createThread,
    84  * ThreadTask::createThreadWithType, ThreadTask::createThreadwithRaceCondition.
     70 * ThreadTask::createThreadWithType.
    8571 *
    8672 * @note Always consumes @a this!
    8773 */
    88 HRESULT ThreadTask::createThreadInternal(RTTHREADTYPE enmType, PRTTHREAD phThread)
     74HRESULT ThreadTask::createThreadInternal(RTTHREADTYPE enmType)
    8975{
    90     RTTHREAD hThread;
    91     int vrc = RTThreadCreate(&hThread,
     76    int vrc = RTThreadCreate(NULL,
    9277                             taskHandlerThreadProc,
    9378                             (void *)this,
     
    9782                             this->getTaskName().c_str());
    9883    if (RT_SUCCESS(vrc))
    99     {
    100         mAsync = true;
    101         if (phThread)
    102             *phThread = hThread;
    10384        return S_OK;
    104     }
    10585
     86    mAsync = false;
    10687    delete this;
    10788    return E_FAIL;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette