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

Task: replace CPLMutex* with std::mutex #9717

Open
rouault opened this issue Apr 21, 2024 · 1 comment
Open

Task: replace CPLMutex* with std::mutex #9717

rouault opened this issue Apr 21, 2024 · 1 comment
Labels
task Planned work (implies someone assigns it to him/her)

Comments

@rouault
Copy link
Member

rouault commented Apr 21, 2024

What is the bug?

Most of our uses of CPMutex* could likely be replaced with standard std::mutex. But caution: CPLMutex* is recursive, while std::mutex is not. In most cases a regular (non-recursive) std::mutex is probably sufficient, but a std::recursive_mutex might be needed in some places

Steps to reproduce the issue

Versions and provenance

Additional context

No response

@rouault rouault added the task Planned work (implies someone assigns it to him/her) label Apr 21, 2024
@rouault
Copy link
Member Author

rouault commented May 2, 2024

We should be careful though if using std::mutex as global variables, for functions that could be called late in the termination sequence of the process, and after the std::mutex have been freed

For example we have this comment in

void CPL_STDCALL GDALDestroyDriverManager(void)

{
    // THREADSAFETY: We would like to lock the mutex here, but it
    // needs to be reacquired within the destructor during driver
    // deregistration.

    // FIXME: Disable following code as it crashed on OSX CI test.
    // std::lock_guard<std::mutex> oLock(oDeleteMutex);

    if (poDM != nullptr)
    {
        delete poDM;
        poDM = nullptr;
    }
}

This dates back to 2016 (2f31c81#diff-8b606e66da439e0d798d0923d6a2f47be064b2a624c292345e08d5b2f994eacd) at a time where GDALDestroy() was called as a GCC ``attribute((destructor ))e8c9bea5dbe8e90d01d575f94a040fcaee27c24f function, before commit e8c9bea in 2018, which no longer runs it automatically on non-MSVC builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Planned work (implies someone assigns it to him/her)
Projects
None yet
Development

No branches or pull requests

1 participant