@@ -225,18 +225,16 @@ void ADIOS2File::finalize()
225
225
{
226
226
return ;
227
227
}
228
+ if (!m_uniquePtrPuts.empty ())
229
+ {
230
+ throw error::Internal (
231
+ " [ADIOS2 backend] Orphaned unique-ptr put operations found "
232
+ " when closing file." );
233
+ }
228
234
// if write accessing, ensure that the engine is opened
229
- // and that all datasets are written
230
- // (attributes and unique_ptr datasets are written upon closing a step
231
- // or a file which users might never do)
232
- bool needToWrite = !m_uniquePtrPuts.empty ();
233
- if ((needToWrite || !m_engine) && writeOnly (m_mode))
235
+ if (!m_engine && writeOnly (m_mode))
234
236
{
235
237
getEngine ();
236
- for (auto &entry : m_uniquePtrPuts)
237
- {
238
- entry.run (*this );
239
- }
240
238
}
241
239
if (m_engine)
242
240
{
@@ -1027,12 +1025,19 @@ void ADIOS2File::flush_impl(
1027
1025
initializedDefaults = true ;
1028
1026
}
1029
1027
1028
+ std::vector<BufferedUniquePtrPut> drainedUniquePtrPuts;
1030
1029
if (writeLatePuts)
1031
1030
{
1032
1031
for (auto &entry : m_uniquePtrPuts)
1033
1032
{
1034
1033
entry.run (*this );
1035
1034
}
1035
+ // Move the operations out of the queue so that no one has ideas to run
1036
+ // them for a second time
1037
+ drainedUniquePtrPuts = std::move (m_uniquePtrPuts);
1038
+ // m_uniquePtrPuts is in a valid, but unspecified state after moving
1039
+ // --> clear it
1040
+ m_uniquePtrPuts.clear ();
1036
1041
}
1037
1042
1038
1043
if (readOnly (m_mode))
@@ -1047,10 +1052,7 @@ void ADIOS2File::flush_impl(
1047
1052
m_updateSpans.clear ();
1048
1053
m_buffer.clear ();
1049
1054
m_alreadyEnqueued.clear ();
1050
- if (writeLatePuts)
1051
- {
1052
- m_uniquePtrPuts.clear ();
1053
- }
1055
+ drainedUniquePtrPuts.clear ();
1054
1056
1055
1057
break ;
1056
1058
0 commit comments