Closed Superpiffer closed 1 year ago
I have this exception in a multi thread application:
Apparently different threads tries to modify this Dictionary: https://github.com/SciSharp/TensorFlow.NET/blob/cd64ea96f31cce51405664023023db94de45f1e7/src/TensorFlowNET.Core/Device/DeviceSpec.cs#L10
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()); }
I can bypass this issue using a ConcurrentDictionary, but I don't know if that's an ideal solution.
Tensorflow.NET v0.100.5 .NET 6.0
ConcurrentDictionary is the good approach. @AsakusaRinne
ConcurrentDictionary
Description
I have this exception in a multi thread application:
Apparently different threads tries to modify this Dictionary: https://github.com/SciSharp/TensorFlow.NET/blob/cd64ea96f31cce51405664023023db94de45f1e7/src/TensorFlowNET.Core/Device/DeviceSpec.cs#L10
Reproduction Steps
Create more than one thread with a new instance of Session per thread:
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