Skip to content

Commit 4899c89

Browse files
committed
Fix a race condition when multiple threads try to create a bml endpoint simultaneously.
1 parent 627a89b commit 4899c89

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ompi/mca/bml/r2/bml_r2.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ static mca_bml_base_endpoint_t *mca_bml_r2_allocate_endpoint (ompi_proc_t *proc)
160160
mca_bml_base_btl_array_reserve(&bml_endpoint->btl_rdma, mca_bml_r2.num_btl_modules);
161161
bml_endpoint->btl_max_send_size = -1;
162162
bml_endpoint->btl_proc = proc;
163-
proc->proc_endpoints[OMPI_PROC_ENDPOINT_TAG_BML] = bml_endpoint;
164163

165164
bml_endpoint->btl_flags_or = 0;
166165
return bml_endpoint;
@@ -430,6 +429,12 @@ static int mca_bml_r2_add_proc (struct ompi_proc_t *proc)
430429
/* compute metrics for registered btls */
431430
mca_bml_r2_compute_endpoint_metrics (bml_endpoint);
432431

432+
/* do it last, for the lazy initialization check in bml_base_get* */
433+
#if OPAL_ENABLE_THREAD_MULTI
434+
opal_atomic_wmb();
435+
#endif /* OPAL_ENABLE_THREAD_MULTI */
436+
proc->proc_endpoints[OMPI_PROC_ENDPOINT_TAG_BML] = bml_endpoint;
437+
433438
return OMPI_SUCCESS;
434439
}
435440

@@ -523,6 +528,7 @@ static int mca_bml_r2_add_procs( size_t nprocs,
523528

524529
if (NULL == bml_endpoint) {
525530
bml_endpoint = mca_bml_r2_allocate_endpoint (proc);
531+
proc->proc_endpoints[OMPI_PROC_ENDPOINT_TAG_BML] = bml_endpoint;
526532
if (NULL == bml_endpoint) {
527533
free(btl_endpoints);
528534
free(new_procs);

0 commit comments

Comments
 (0)