Skip to content

Commit f96305f

Browse files
authored
Merge pull request #6199 from aravindksg/opal-threads-fix
opal/sync: Fix assert during multi-threaded progress invocation
2 parents cf49957 + 2f3c521 commit f96305f

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

opal/threads/wait_sync.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
4747
}
4848

4949
/* Insert sync on the list of pending synchronization constructs */
50-
OPAL_THREAD_LOCK(&wait_sync_lock);
51-
if( NULL == wait_sync_list ) {
52-
sync->next = sync->prev = sync;
53-
wait_sync_list = sync;
54-
} else {
55-
sync->prev = wait_sync_list->prev;
56-
sync->prev->next = sync;
57-
sync->next = wait_sync_list;
58-
wait_sync_list->prev = sync;
50+
if (num_thread_in_progress >= opal_max_thread_in_progress) {
51+
OPAL_THREAD_LOCK(&wait_sync_lock);
52+
if( NULL == wait_sync_list ) {
53+
sync->next = sync->prev = sync;
54+
wait_sync_list = sync;
55+
} else {
56+
sync->prev = wait_sync_list->prev;
57+
sync->prev->next = sync;
58+
sync->next = wait_sync_list;
59+
wait_sync_list->prev = sync;
60+
}
61+
OPAL_THREAD_UNLOCK(&wait_sync_lock);
5962
}
60-
OPAL_THREAD_UNLOCK(&wait_sync_lock);
6163

6264
/**
6365
* If we are not responsible for progresing, go silent until something worth noticing happen:
@@ -89,20 +91,23 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
8991
}
9092
OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1);
9193

92-
assert(sync == wait_sync_list);
94+
if (NULL != wait_sync_list) {
95+
assert(sync == wait_sync_list);
96+
}
9397

9498
i_am_done:
9599
/* My sync is now complete. Trim the list: remove self, wake next */
96-
OPAL_THREAD_LOCK(&wait_sync_lock);
97-
sync->prev->next = sync->next;
98-
sync->next->prev = sync->prev;
99-
/* In case I am the progress manager, pass the duties on */
100-
if( sync == wait_sync_list ) {
101-
wait_sync_list = (sync == sync->next) ? NULL : sync->next;
102-
if( NULL != wait_sync_list )
103-
WAIT_SYNC_PASS_OWNERSHIP(wait_sync_list);
100+
if (num_thread_in_progress >= opal_max_thread_in_progress) {
101+
OPAL_THREAD_LOCK(&wait_sync_lock);
102+
sync->prev->next = sync->next;
103+
sync->next->prev = sync->prev;
104+
/* In case I am the progress manager, pass the duties on */
105+
if( sync == wait_sync_list ) {
106+
wait_sync_list = (sync == sync->next) ? NULL : sync->next;
107+
if( NULL != wait_sync_list )
108+
WAIT_SYNC_PASS_OWNERSHIP(wait_sync_list);
109+
}
110+
OPAL_THREAD_UNLOCK(&wait_sync_lock);
104111
}
105-
OPAL_THREAD_UNLOCK(&wait_sync_lock);
106-
107112
return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR;
108113
}

0 commit comments

Comments
 (0)