Skip to content

Commit dabdfe7

Browse files
committed
grequestx: fix race condition in initialization
Signed-off-by: Joseph Schuchart <[email protected]>
1 parent 4a39a34 commit dabdfe7

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

ompi/request/grequestx.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static bool requests_initialized = false;
3030
static opal_list_t requests;
3131
static opal_atomic_int32_t active_requests = 0;
3232
static bool in_progress = false;
33-
static opal_mutex_t lock;
33+
static opal_mutex_t lock = OPAL_MUTEX_STATIC_INIT;
3434

3535
static int grequestx_progress(void) {
3636
ompi_grequest_t *request, *next;
@@ -79,13 +79,12 @@ int ompi_grequestx_start(
7979
*/
8080
OBJ_RETAIN(((ompi_grequest_t *)*request));
8181

82+
OPAL_THREAD_LOCK(&lock);
8283
if (!requests_initialized) {
8384
OBJ_CONSTRUCT(&requests, opal_list_t);
84-
OBJ_CONSTRUCT(&lock, opal_mutex_t);
8585
requests_initialized = true;
8686
}
8787

88-
OPAL_THREAD_LOCK(&lock);
8988
opal_list_append(&requests, &((*request)->super.super));
9089
OPAL_THREAD_UNLOCK(&lock);
9190
int32_t tmp = OPAL_THREAD_ADD_FETCH32(&active_requests, 1);

0 commit comments

Comments
 (0)