Skip to content

Commit

Permalink
Avoid static initialization of recursive mutexes
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bosilca committed Oct 30, 2023
1 parent 14ecf5d commit ad4c825
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ompi/instance/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@

ompi_predefined_instance_t ompi_mpi_instance_null = {{{{0}}}};

#if defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT)
static opal_recursive_mutex_t instance_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT;
#else
static opal_recursive_mutex_t instance_lock;
__attribute__((__constructor__)) static void instance_lock_init(void) {
OBJ_CONSTRUCT(&instance_lock, opal_recursive_mutex_t);
}
#endif /* defined(OPAL_RECURSIVE_MUTEX_STATIC_INIT) */

/** MPI_Init instance */
ompi_instance_t *ompi_mpi_instance_default = NULL;
Expand Down
2 changes: 1 addition & 1 deletion opal/mca/btl/usnic/btl_usnic_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
#define OPAL_BTL_USNIC_NUM_COMPLETIONS 500

/* MPI_THREAD_MULTIPLE_SUPPORT */
opal_recursive_mutex_t btl_usnic_lock = OPAL_RECURSIVE_MUTEX_STATIC_INIT;
opal_recursive_mutex_t btl_usnic_lock; /* recursive mutexes must be dynamically initialized */

/* RNG buffer definition */
opal_rng_buff_t opal_btl_usnic_rand_buff = {{0}};
Expand Down

0 comments on commit ad4c825

Please sign in to comment.