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 );
0 commit comments