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

Gate deadlock #2540

Open
ghlk12345 opened this issue May 19, 2024 · 2 comments
Open

Gate deadlock #2540

ghlk12345 opened this issue May 19, 2024 · 2 comments
Assignees
Labels
feature Approved feature - build it

Comments

@ghlk12345
Copy link

ghlk12345 commented May 19, 2024

osgEarth Version (required): master

need bug fix file: Threading.
If we request uri resource in one thread, then node reader implement use the same uri path construct URI in the same thread, the new URI's doRead func construct gatelock will be deadlock。for example, the ReaderWriterGLTF read a B3DM file.

I have a solution

template<typename T>
class Gate
{
public:
    Gate() { }

    inline void lock(const T& key) {
        std::unique_lock<std::mutex> lock(_m);
        for (;;) {
            auto i = _keys.emplace(key, std::this_thread::get_id());
            if (i.second == true || i.first->second == std::this_thread::get_id()) // insert successful or same thread call
                return;
            _unlocked.wait(lock);
        }
    }

    inline void unlock(const T& key) {
        std::unique_lock<std::mutex> lock(_m);
        _keys.erase(key);
        _unlocked.notify_all();
    }

private:
    std::mutex _m;
    std::condition_variable_any _unlocked;
    std::unordered_map<T, std::thread::id> _keys;
};
@gwaldron
Copy link
Owner

Where are you seeing this happen? Seems like this would only happen if you try to load the same file recursively...?

@ghlk12345
Copy link
Author

Where are you seeing this happen? Seems like this would only happen if you try to load the same file recursively...?

OSGEarth have some situation to make it happen.
Forexample, the 3dtiles's layer read layer's json file , then it will use URI read all things when layer open, include b3dm file. Then it will read b3dm file recursive, the first by 3dtiles layer, the second by gltf plugin

@gwaldron gwaldron self-assigned this May 24, 2024
@gwaldron gwaldron added the feature Approved feature - build it label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Approved feature - build it
Projects
None yet
Development

No branches or pull requests

2 participants