Skip to content

Commit ce3a73f

Browse files
authored
Merge pull request #2104 from jsquyres/pr/v2.x/mt-fix
v2.x: Fix MT wait-sync.
2 parents e4df05d + 86142d5 commit ce3a73f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

opal/threads/wait_sync.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,24 @@ static ompi_wait_sync_t* wait_sync_list = NULL;
2525

2626
int sync_wait_mt(ompi_wait_sync_t *sync)
2727
{
28+
/* Don't stop if the waiting synchronization is completed. We avoid the
29+
* race condition around the release of the synchronization using the
30+
* signaling field.
31+
*/
2832
if(sync->count <= 0)
2933
return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR;
3034

3135
/* lock so nobody can signal us during the list updating */
3236
pthread_mutex_lock(&sync->lock);
3337

38+
/* Now that we hold the lock make sure another thread has not already
39+
* call cond_signal.
40+
*/
41+
if(sync->count <= 0) {
42+
pthread_mutex_unlock(&sync->lock);
43+
return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR;
44+
}
45+
3446
/* Insert sync on the list of pending synchronization constructs */
3547
OPAL_THREAD_LOCK(&wait_sync_lock);
3648
if( NULL == wait_sync_list ) {

0 commit comments

Comments
 (0)