@@ -27,18 +27,18 @@ int sync_wait_st(ompi_wait_sync_t *sync)
2727 while (sync -> count > 0 ) {
2828 opal_progress ();
2929 }
30- return OPAL_SUCCESS ;
30+ return ( 0 == sync -> status ) ? OPAL_SUCCESS : OPAL_ERROR ;
3131}
3232
3333int sync_wait_mt (ompi_wait_sync_t * sync )
3434{
3535 if (sync -> count <= 0 )
36- return OPAL_SUCCESS ;
36+ return ( 0 == sync -> status ) ? OPAL_SUCCESS : OPAL_ERROR ;
3737
3838 /* lock so nobody can signal us during the list updating */
3939 pthread_mutex_lock (& sync -> lock );
4040
41- /* Insert sync to the list */
41+ /* Insert sync on the list of pending synchronization constructs */
4242 OPAL_THREAD_LOCK (& wait_sync_lock );
4343 if ( NULL == wait_sync_list ) {
4444 sync -> next = sync -> prev = sync ;
@@ -52,32 +52,34 @@ int sync_wait_mt(ompi_wait_sync_t *sync)
5252 OPAL_THREAD_UNLOCK (& wait_sync_lock );
5353
5454 /**
55- * If we are not responsible for progresing, let's go silent until something worth noticing happen:
55+ * If we are not responsible for progresing, go silent until something worth noticing happen:
5656 * - this thread has been promoted to take care of the progress
5757 * - our sync has been triggered.
5858 */
59+ check_status :
5960 if ( sync != wait_sync_list ) {
6061 pthread_cond_wait (& sync -> condition , & sync -> lock );
6162
6263 /**
63- * At this point either the sync was completed in which case we should remove it from the wait
64- * list, or/and I was promoted as the progress manager.
64+ * At this point either the sync was completed in which case
65+ * we should remove it from the wait list, or/and I was
66+ * promoted as the progress manager.
6567 */
6668
6769 if ( sync -> count <= 0 ) { /* Completed? */
6870 pthread_mutex_unlock (& sync -> lock );
6971 goto i_am_done ;
7072 }
71- /* promoted ! */
72- assert ( sync == wait_sync_list ) ;
73+ /* either promoted, or spurious wakeup ! */
74+ goto check_status ;
7375 }
7476
7577 pthread_mutex_unlock (& sync -> lock );
7678 while (sync -> count > 0 ) { /* progress till completion */
7779 opal_progress (); /* don't progress with the sync lock locked or you'll deadlock */
7880 }
79-
8081 assert (sync == wait_sync_list );
82+
8183 i_am_done :
8284 /* My sync is now complete. Trim the list: remove self, wake next */
8385 OPAL_THREAD_LOCK (& wait_sync_lock );
@@ -91,5 +93,5 @@ int sync_wait_mt(ompi_wait_sync_t *sync)
9193 }
9294 OPAL_THREAD_UNLOCK (& wait_sync_lock );
9395
94- return OPAL_SUCCESS ;
96+ return ( 0 == sync -> status ) ? OPAL_SUCCESS : OPAL_ERROR ;
9597}
0 commit comments