Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid static initialization of recursive mutexes #12034

Conversation

bosilca
Copy link
Member

@bosilca bosilca commented Oct 30, 2023

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.

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 open-mpi#12029.

Signed-off-by: George Bosilca <[email protected]>
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor attribute isn't part of the C standard so we should check if it is actually available. What do we do if it isn't?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All platforms supporting PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP or PTHREAD_RECURSIVE_MUTEX_INITIALIZER remain covered as before. The ones where they are not defined but where we have constructor will be now covered. For the rest of them, one could argue that we could provide support for .init but that would be more than what I'm willing to invest in this.

There is a single instance of a statically initialized recursive mutex. It is not clear to me why the instance code needs a recursive mutex, but I'm not going to dig deeper.

The only remaining statically initialized recursive mutex has now
support for the constructor attribute.

Signed-off-by: George Bosilca <[email protected]>
@jsquyres
Copy link
Member

@bosilca Ok to merge and cherry pick to v5.0.x?

@bosilca bosilca merged commit ee747c6 into open-mpi:main Nov 9, 2023
8 checks passed
@bosilca bosilca deleted the topic/fixes_static_initialization_of_recursive_mutexes branch November 9, 2023 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants