You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ThreadSafeTest.cs 1.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using Tensorflow;
  10. using static Tensorflow.Binding;
  11. namespace TensorFlowNET.UnitTest.Basics
  12. {
  13. [TestClass]
  14. public class ThreadSafeTest
  15. {
  16. [TestMethod]
  17. public void GraphWithMultiThreads()
  18. {
  19. List<Thread> threads = new List<Thread>();
  20. const int THREADS_COUNT = 5;
  21. for (int t = 0; t < THREADS_COUNT; t++)
  22. {
  23. Thread thread = new Thread(() =>
  24. {
  25. Graph g = new Graph();
  26. Session session = new Session(g);
  27. session.as_default();
  28. var input = tf.placeholder(tf.int32, shape: new Shape(6));
  29. var op = tf.reshape(input, new int[] { 2, 3 });
  30. });
  31. thread.Start();
  32. threads.Add(thread);
  33. }
  34. threads.ForEach(t => t.Join());
  35. }
  36. }
  37. }