mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-30 09:00:20 -05:00
Addresses race condition in object creation
Ensures thread-safe initialization of PDM objects when created in parallel. Avoids a potential race condition during the first instantiation of a PDM object in a multi-threaded environment. This is achieved by creating a dummy object in the main thread to trigger the necessary initialization before parallel creation begins. Adds a unit test to verify the fix.
This commit is contained in:
1 parent
60c5045c76
commit
54fdf026f4
2 files changed
+35
No files matched your search
@@ -257,6 +257,14 @@ void RimSummaryAddressCollection::updateFolderStructure( const std::set<RifEclip
|
||||
std::vector<RimSummaryAddress*> rimAddresses;
|
||||
rimAddresses.resize( sortedAddresses.size() );
|
||||
|
||||
// Make sure that the first object is created in the main thread. This is needed to avoid a race condition related to initialization of
|
||||
// static data for a PDM object.
|
||||
// See CreateObjectInMultipleThreads test in cafPdmBasicTest.cpp
|
||||
// This is a workaround until initialization of PDM objects is thread safe.
|
||||
{
|
||||
RimSummaryAddress dummyObject;
|
||||
}
|
||||
|
||||
#pragma omp parallel for
|
||||
for ( int i = 0; i < static_cast<int>( sortedAddresses.size() ); ++i )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user