Changeset 2164


Ignore:
Timestamp:
6/13/2010 3:58:53 AM (2 years ago)
Author:
lowjoel
Message:

Fixed potential crash when ResolveHandleName? is called by two threads at the same time (since the initialisation order of the Handle is undefined)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser.Util.Native/OpenHandle.NameResolver.cpp

    r1812 r2164  
    2626 
    2727namespace { 
    28     HANDLE NameResolutionThread; 
    29     NameResolutionThreadParams NameResolutionThreadParam; 
    30  
    3128    DWORD __stdcall nameResolutionThread(void* data) 
    3229    { 
     
    10198        handle = CreateThread(NULL, 0, nameResolutionThread, &params, 0, NULL); 
    10299    } 
    103  
    104100} 
    105101 
    106102std::wstring ResolveHandleName(HANDLE handle, int pid) 
    107103{ 
     104    static HANDLE thread = NULL; 
     105    static NameResolutionThreadParams params; 
     106 
    108107    //Start a name resolution thread (in case one entry hangs) 
    109     if (NameResolutionThread == NULL) 
    110         CreateNameThread(NameResolutionThread, NameResolutionThreadParam); 
     108    if (thread == NULL) 
     109        CreateNameThread(thread, params); 
    111110 
    112111    //Create a duplicate handle 
     
    123122    //Send the handle to the secondary thread for name resolution 
    124123    NameResult result(localHandle); 
    125     NameResolutionThreadParam.Input.push_back(&result); 
    126     ReleaseSemaphore(NameResolutionThreadParam.Semaphore, 1, NULL); 
     124    params.Input.push_back(&result); 
     125    ReleaseSemaphore(params.Semaphore, 1, NULL); 
    127126 
    128127    //Wait for the result 
     
    130129    { 
    131130        //The wait failed. Terminate the thread and recreate another. 
    132         CreateNameThread(NameResolutionThread, NameResolutionThreadParam); 
     131        CreateNameThread(thread, params); 
    133132    } 
    134133 
Note: See TracChangeset for help on using the changeset viewer.