Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG Report]: v0.100.5 is not thread safe anymore #1066

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

Closed
Superpiffer opened this issue May 11, 2023 · 1 comment · Fixed by #1068
Closed

[BUG Report]: v0.100.5 is not thread safe anymore #1066

Superpiffer opened this issue May 11, 2023 · 1 comment · Fixed by #1068
Assignees
Labels
bug Something isn't working

Comments

@Superpiffer
Copy link
Contributor

Description

I have this exception in a multi thread application:
image

Apparently different threads tries to modify this Dictionary:

private static Dictionary<string, Components> _STRING_TO_COMPONENTS_CACHE = new();

Reproduction Steps

Create more than one thread with a new instance of Session per thread:

private static void TestThreads()
{
    List<Thread> threads = new List<Thread>();

    const int THREADS_COUNT = 5;

    for(int t = 0; t < THREADS_COUNT; t++)
    {
        Thread thread = new Thread(() =>
        {
            Graph g = new Graph();
            g.Import("model.pb");
            Session session = new Session(g);
        });
        thread.Start();
        threads.Add(thread);
    }

    threads.ForEach(t => t.Join());
}

Known Workarounds

I can bypass this issue using a ConcurrentDictionary, but I don't know if that's an ideal solution.

Configuration and Other Information

Tensorflow.NET v0.100.5
.NET 6.0

@Oceania2018
Copy link
Member

ConcurrentDictionary is the good approach. @AsakusaRinne

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants