[m-rev.] for review: Reset es_action field when idle ws engine receives a notification.

Peter Wang novalazy at gmail.com
Mon Apr 20 13:28:17 AEST 2020


In MR_do_idle_worksteal, reset the engine's es_action field to
MR_ENGINE_ACTION_NONE before performing the notified action.
This mirrors the behaviour in MR_do_sleep.

Fixes the assertion failure in Mantis bug #461: when an engine is
shut down, MR_verify_final_engine_sleep_sync checks that the engine's
es_action field is MR_ENGINE_ACTION_NONE.

runtime/mercury_context.c:
    As above.

NEWS:
    Announce change.
---
 NEWS                      | 3 +++
 runtime/mercury_context.c | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index df5671af7..1f87e379a 100644
--- a/NEWS
+++ b/NEWS
@@ -263,6 +263,9 @@ Changes to the Mercury implementation
 
 * We have upgraded the bundled Boehm GC to v7.6.12 and libatomic_ops to v7.6.8.
 
+* [Mantis bug #461]. We have fixed an assertion failure affecting programs
+  in low-level C parallel grades as they exit.
+
 NEWS for Mercury 20.01.2
 ========================
 
diff --git a/runtime/mercury_context.c b/runtime/mercury_context.c
index 106f91e68..2070f6ca1 100644
--- a/runtime/mercury_context.c
+++ b/runtime/mercury_context.c
@@ -2279,6 +2279,7 @@ MR_define_entry(MR_do_idle_worksteal);
     MR_Code             *jump_target;
     MR_EngineId         engine_id = MR_ENGINE(MR_eng_id);
     engine_sleep_sync   *esync = get_engine_sleep_sync(engine_id);
+    unsigned            action;
 
     // Only work-stealing engines beyond this point.
     MR_assert(MR_ENGINE(MR_eng_type) == MR_ENGINE_TYPE_SHARED);
@@ -2290,8 +2291,10 @@ MR_define_entry(MR_do_idle_worksteal);
         }
 
         // The compare and swap failed, which means there is a notification.
+        action = esync->d.es_action;
+        esync->d.es_action = MR_ENGINE_ACTION_NONE;
 
-        switch (esync->d.es_action) {
+        switch (action) {
             case MR_ENGINE_ACTION_SHUTDOWN:
                 action_shutdown_ws_engine();
 
-- 
2.25.0



More information about the reviews mailing list