Skip to content

Commit db1239a

Browse files
authored
Merge pull request #6479 from abouteiller/backport/5975/v3.0.x
v3.0.x: Avoid a double lock interlock when calling pmix_finalize
2 parents a194870 + 56a9883 commit db1239a

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

opal/mca/pmix/pmix2x/pmix2x_client.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
99
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
1010
* reserved.
11+
* Copyright (c) 2018 The University of Tennessee and The University
12+
* of Tennessee Research Foundation. All rights
13+
* reserved.
1114
* $COPYRIGHT$
1215
*
1316
* Additional copyrights may follow
@@ -167,6 +170,8 @@ int pmix2x_client_finalize(void)
167170
{
168171
pmix_status_t rc;
169172
opal_pmix2x_event_t *event, *ev2;
173+
opal_list_t evlist;
174+
OBJ_CONSTRUCT(&evlist, opal_list_t);
170175

171176
opal_output_verbose(1, opal_pmix_base_framework.framework_output,
172177
"PMIx_client finalize");
@@ -180,13 +185,19 @@ int pmix2x_client_finalize(void)
180185
OPAL_PMIX_DESTRUCT_LOCK(&event->lock);
181186
OPAL_PMIX_CONSTRUCT_LOCK(&event->lock);
182187
PMIx_Deregister_event_handler(event->index, dereg_cbfunc, (void*)event);
183-
OPAL_PMIX_WAIT_THREAD(&event->lock);
184188
opal_list_remove_item(&mca_pmix_pmix2x_component.events, &event->super);
185-
OBJ_RELEASE(event);
189+
/* wait and release outside the loop to avoid double mutex
190+
* interlock */
191+
opal_list_append(&evlist, &event->super);
186192
}
187193
}
188194
OPAL_PMIX_RELEASE_THREAD(&opal_pmix_base.lock);
189-
195+
OPAL_LIST_FOREACH_SAFE(event, ev2, &evlist, opal_pmix2x_event_t) {
196+
OPAL_PMIX_WAIT_THREAD(&event->lock);
197+
opal_list_remove_item(&evlist, &event->super);
198+
OBJ_RELEASE(event);
199+
}
200+
OBJ_DESTRUCT(&evlist);
190201
rc = PMIx_Finalize(NULL, 0);
191202

192203
return pmix2x_convert_rc(rc);

opal/mca/pmix/pmix2x/pmix2x_server_south.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
1010
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
1111
* reserved.
12+
* Copyright (c) 2018 The University of Tennessee and The University
13+
* of Tennessee Research Foundation. All rights
14+
* reserved.
1215
* $COPYRIGHT$
1316
*
1417
* Additional copyrights may follow
@@ -179,6 +182,8 @@ int pmix2x_server_finalize(void)
179182
{
180183
pmix_status_t rc;
181184
opal_pmix2x_event_t *event, *ev2;
185+
opal_list_t evlist;
186+
OBJ_CONSTRUCT(&evlist, opal_list_t);
182187

183188
OPAL_PMIX_ACQUIRE_THREAD(&opal_pmix_base.lock);
184189
--opal_pmix_base.initialized;
@@ -189,13 +194,19 @@ int pmix2x_server_finalize(void)
189194
OPAL_PMIX_DESTRUCT_LOCK(&event->lock);
190195
OPAL_PMIX_CONSTRUCT_LOCK(&event->lock);
191196
PMIx_Deregister_event_handler(event->index, dereg_cbfunc, (void*)event);
192-
OPAL_PMIX_WAIT_THREAD(&event->lock);
193197
opal_list_remove_item(&mca_pmix_pmix2x_component.events, &event->super);
194-
OBJ_RELEASE(event);
198+
/* wait and release outside the loop to avoid double mutex
199+
* interlock */
200+
opal_list_append(&evlist, &event->super);
195201
}
196202
}
197203
OPAL_PMIX_RELEASE_THREAD(&opal_pmix_base.lock);
198-
204+
OPAL_LIST_FOREACH_SAFE(event, ev2, &evlist, opal_pmix2x_event_t) {
205+
OPAL_PMIX_WAIT_THREAD(&event->lock);
206+
opal_list_remove_item(&evlist, &event->super);
207+
OBJ_RELEASE(event);
208+
}
209+
OBJ_DESTRUCT(&evlist);
199210
rc = PMIx_server_finalize();
200211
return pmix2x_convert_rc(rc);
201212
}

0 commit comments

Comments
 (0)