Skip to content

Commit ad4c825

Browse files
committed
Avoid static initialization of recursive mutexes
There is no portable way to statically initialize recursive mutexes. Where possible avoid doing so, and where not possible add a specialized __constructor__ (thanks @eschnett for the patch). Fixes #12029. Signed-off-by: George Bosilca <bosilca@icl.utk.edu>
1 parent 14ecf5d commit ad4c825

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

ompi/instance/instance.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@
5959

6060
ompi_predefined_instance_t ompi_mpi_instance_null = {{{{0}}}};
6161

62+
#if defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT)
6263
static opal_recursive_mutex_t instance_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT;
64+
#else
65+
static opal_recursive_mutex_t instance_lock;
66+
__attribute__((__constructor__)) static void instance_lock_init(void) {
67+
OBJ_CONSTRUCT(&instance_lock, opal_recursive_mutex_t);
68+
}
69+
#endif /* defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT) */
6370

6471
/** MPI_Init instance */
6572
ompi_instance_t *ompi_mpi_instance_default = NULL;

opal/mca/btl/usnic/btl_usnic_component.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
#define OPAL_BTL_USNIC_NUM_COMPLETIONS 500
8484

8585
/* MPI_THREAD_MULTIPLE_SUPPORT */
86-
opal_recursive_mutex_t btl_usnic_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT;
86+
opal_recursive_mutex_t btl_usnic_lock; /* recursive mutexes must be dynamically initialized */
8787

8888
/* RNG buffer definition */
8989
opal_rng_buff_t opal_btl_usnic_rand_buff = {{0}};

0 commit comments

Comments
 (0)