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) 2017-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
@@ -169,6 +172,8 @@ int pmix4x_client_finalize(void)
169172{
170173 pmix_status_t rc ;
171174 opal_pmix4x_event_t * event , * ev2 ;
175+ opal_list_t evlist ;
176+ OBJ_CONSTRUCT (& evlist , opal_list_t );
172177
173178 opal_output_verbose (1 , opal_pmix_base_framework .framework_output ,
174179 "PMIx_client finalize" );
@@ -182,12 +187,19 @@ int pmix4x_client_finalize(void)
182187 OPAL_PMIX_DESTRUCT_LOCK (& event -> lock );
183188 OPAL_PMIX_CONSTRUCT_LOCK (& event -> lock );
184189 PMIx_Deregister_event_handler (event -> index , dereg_cbfunc , (void * )event );
185- OPAL_PMIX_WAIT_THREAD (& event -> lock );
186190 opal_list_remove_item (& mca_pmix_pmix4x_component .events , & event -> super );
187- OBJ_RELEASE (event );
191+ /* wait and release outside the loop to avoid double mutex
192+ * interlock */
193+ opal_list_append (& evlist , & event -> super );
188194 }
189195 }
190196 OPAL_PMIX_RELEASE_THREAD (& opal_pmix_base .lock );
197+ OPAL_LIST_FOREACH_SAFE (event , ev2 , & evlist , opal_pmix4x_event_t ) {
198+ OPAL_PMIX_WAIT_THREAD (& event -> lock );
199+ opal_list_remove_item (& evlist , & event -> super );
200+ OBJ_RELEASE (event );
201+ }
202+ OBJ_DESTRUCT (& evlist );
191203 rc = PMIx_Finalize (NULL , 0 );
192204
193205 return pmix4x_convert_rc (rc );
0 commit comments