Skip to content

Commit 391370a

Browse files
authored
Merge pull request #7546 from devreal/egrequest-obj-retain
grequestx: fix racy initialization and premature destruction
2 parents b560fc5 + dabdfe7 commit 391370a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ompi/request/grequestx.c

Lines changed: 8 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;
@@ -47,6 +47,7 @@ static int grequestx_progress(void) {
4747
OPAL_THREAD_LOCK(&lock);
4848
if (REQUEST_COMPLETE(&request->greq_base)) {
4949
opal_list_remove_item(&requests, &request->greq_base.super.super);
50+
OBJ_RELEASE(request);
5051
completed++;
5152
}
5253
}
@@ -73,13 +74,17 @@ int ompi_grequestx_start(
7374
}
7475
((ompi_grequest_t *)*request)->greq_poll.c_poll = gpoll_fn;
7576

77+
/* prevent the request from being destroyed upon completion,
78+
* we first have to remove it from the list of active requests
79+
*/
80+
OBJ_RETAIN(((ompi_grequest_t *)*request));
81+
82+
OPAL_THREAD_LOCK(&lock);
7683
if (!requests_initialized) {
7784
OBJ_CONSTRUCT(&requests, opal_list_t);
78-
OBJ_CONSTRUCT(&lock, opal_mutex_t);
7985
requests_initialized = true;
8086
}
8187

82-
OPAL_THREAD_LOCK(&lock);
8388
opal_list_append(&requests, &((*request)->super.super));
8489
OPAL_THREAD_UNLOCK(&lock);
8590
int32_t tmp = OPAL_THREAD_ADD_FETCH32(&active_requests, 1);

0 commit comments

Comments
 (0)