Changeset 10941 for trunk/FACT++


Ignore:
Timestamp:
06/09/11 10:47:58 (13 years ago)
Author:
tbretz
Message:
Fixed a dead-lock in the mutex by replacing it with the global dim-lock mechanism.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/MessageDim.cc

    r10919 r10941  
    6868int MessageDimTX::Write(const Time &t, const string &txt, int qos)
    6969{
    70     static mutex mtx;
     70    MessageImp::Write(t, txt, qos);
    7171
    72     mtx.lock();
    7372
    74     MessageImp::Write(t, txt, qos);
     73    // We cannot use our own mutex here because it can create dead-locks
     74    // in a hand-shake with the global dim-mutex if a service is
     75    // updated from within a dimHandler (dim-mutex already locked)
     76    // and at the same time another thread tries to lock the mutex.
     77    //
     78    // Thread 1: Lock global Dim mutex and call infoHandler
     79    //
     80    // Thread 2: CALL Write
     81    // Thread 2: LOCK Write-mutex
     82    // Thread 2: setQuality will try to lock global Dim mutex
     83    //           (since Thread1!=Thread2 this results in a wait)
     84    //
     85    // Thread 1: CALL Write from within the infoHandler
     86    // Thread 1: LOCK Write-mutex
     87    //           (since Thread2 now waits for the infoHandler to finish
     88    //            and the infoHandler has to wait for the Write-mutex
     89    //            we have a dead-lock)
     90    //
     91    extern void dim_lock();
     92    extern void dim_unlock();
     93
     94    dim_lock();
    7595
    7696    // We have to use setData to make sure the DimService will
    7797    // hold a local copy of the data.
     98    setData(const_cast<char*>(txt.c_str()));
    7899    setQuality(qos);
    79     setData(const_cast<char*>(txt.c_str()));
     100
    80101    const int rc = updateService();
     102
     103    dim_unlock();
    81104
    82105    if (rc==0 && fDebug)
    83106        Out() << " !! " << t.GetAsStr() << " - Sending failed!" << endl;
    84 
    85     mtx.unlock();
    86107
    87108    return rc;
Note: See TracChangeset for help on using the changeset viewer.