Skip to content

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

Closed
@Superpiffer

Description

@Superpiffer

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions