Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit a7e27ef

Browse files
committed
Merge pull request #1162 from abouteiller/bug/v2.x/mt_lazy_addproc
bug fix: race condition when multiple threads create the same endpoint simultaneously
2 parents 5065fd0 + b03ef3c commit a7e27ef

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

ompi/mca/bml/r2/bml_r2.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2014 The University of Tennessee and The University
6+
* Copyright (c) 2004-2016 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -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);

ompi/mca/pml/ob1/pml_ob1_comm.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2006 The University of Tennessee and The University
6+
* Copyright (c) 2004-2016 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
@@ -73,10 +73,11 @@ static inline mca_pml_ob1_comm_proc_t *mca_pml_ob1_peer_lookup (struct ompi_comm
7373
if (OPAL_UNLIKELY(NULL == pml_comm->procs[rank])) {
7474
OPAL_THREAD_LOCK(&pml_comm->proc_lock);
7575
if (NULL == pml_comm->procs[rank]) {
76-
pml_comm->procs[rank] = OBJ_NEW(mca_pml_ob1_comm_proc_t);
77-
pml_comm->procs[rank]->ompi_proc = ompi_comm_peer_lookup (comm, rank);
78-
OBJ_RETAIN(pml_comm->procs[rank]->ompi_proc);
76+
mca_pml_ob1_comm_proc_t* proc = OBJ_NEW(mca_pml_ob1_comm_proc_t);
77+
proc->ompi_proc = ompi_comm_peer_lookup (comm, rank);
78+
OBJ_RETAIN(proc->ompi_proc);
7979
opal_atomic_wmb ();
80+
pml_comm->procs[rank] = proc;
8081
}
8182
OPAL_THREAD_UNLOCK(&pml_comm->proc_lock);
8283
}

0 commit comments

Comments
 (0)