Skip to content

Commit

Permalink
Fix race condition in ParameterMap
Browse files Browse the repository at this point in the history
If threads are competing to try and both check and update the map then
they will hit the appropriate PARALLEL_CRITICAL sections within the
relevant methods. The bug was that the critical sections all had different
names and so OpenMP would not block on an ::add while a ::get is being
performed. The critical secctions are renamed to reflect the what
they are protecting.
Refs #10375
  • Loading branch information
martyngigg committed Oct 16, 2014
1 parent 8dd7a40 commit 63e43e0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp
Expand Up @@ -331,7 +331,7 @@ namespace Mantid
// can not add null pointer
if(!par)return;

PARALLEL_CRITICAL(parameter_add)
PARALLEL_CRITICAL(m_mapAccess)
{
auto existing_par = positionOf(comp,par->name().c_str(),"");
// As this is only an add method it should really throw if it already exists.
Expand Down Expand Up @@ -654,16 +654,16 @@ namespace Mantid
Parameter_sptr result;
if(!comp) return result;

PARALLEL_CRITICAL(ParameterMap_get)
PARALLEL_CRITICAL(m_mapAccess)
{
auto itr = positionOf(comp,name, type);
if (itr != m_map.end())
result = itr->second;
}
return result;
}
/**Return an iterator pointing to a named parameter of a given type.

/**Return an iterator pointing to a named parameter of a given type.
* @param comp :: Component to which parameter is related
* @param name :: Parameter name
* @param type :: An optional type string. If empty, any type is returned
Expand Down Expand Up @@ -739,7 +739,7 @@ namespace Mantid
Parameter_sptr ParameterMap::getByType(const IComponent* comp, const std::string& type) const
{
Parameter_sptr result = Parameter_sptr();
PARALLEL_CRITICAL(ParameterMap_get)
PARALLEL_CRITICAL(m_mapAccess)
{
if( !m_map.empty() )
{
Expand All @@ -763,7 +763,7 @@ namespace Mantid
} // found->firdst
} // it_found != m_map.end()
} //!m_map.empty()
} // PARALLEL_CRITICAL(ParameterMap_get)
} // PARALLEL_CRITICAL(m_map_access)
return result;
}

Expand Down

0 comments on commit 63e43e0

Please sign in to comment.