Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    1,317

    [OpenMP/C++] Problema di race condition

    Ho un problema di race condition qui:
    codice:
        bool clusterExists(std::string& infoSet) {
            bool exists {false};
    #pragma omp critical
            exists = mInfoMap.find(infoSet) != mInfoMap.end();
    
    
            return exists;
        }
    
    
        InfoSet* get(std::string& infoSet, const int& numActs, Env::History& actions) {
            if (numActs > 0 && mCreateNotExists && !clusterExists(infoSet)) {
    #pragma omp critical
        {
                mInfoMap.insert({infoSet, new InfoSet {numActs}});
    
    
                for (auto& a : actions) {
                    mInfoMap[infoSet]->insertActStr(Env::ActToStr(std::get<1>(a)), std::get<2>(a));
                }
        }
            }
    
    
            return mInfoMap[infoSet];
        }

    Penso che il problema sia su "mInfoMap.insert({infoSet, new InfoSet {numActs}});"


    Ma non ne sono certo.


    Dove sbaglio?
    Logiqo.org gestionale per perizie infortunistiche.

  2. #2
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    1,317
    Cercando a lungo ho trovato:
    STL containers are not intrinsically thread-safe. You need to protect access to them using a synchronization mechanism. The typical ones could be a semaphore or a mutex, with the mutex being in general the faster of the two.

    Il problema è questo?
    Anche se non mi è chiaro perchè visto che nel "critical" c'è tutta una porzione di codice.
    Logiqo.org gestionale per perizie infortunistiche.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.