test1.d 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. alias uint8 = ubyte;
  2. import std.stdio;
  3. import std.concurrency : spawn;
  4. import core.time : Duration, dur;
  5. import core.thread;
  6. //void test1_worker(uint8 n){
  7. void test1_worker(int n){
  8. writeln("started worker = ", n);
  9. Thread.sleep(dur!"seconds"(120));
  10. writeln("stopped worker = ", n);
  11. }
  12. void test1_spawner(){
  13. uint8 i = 10; // 10 = 1.7 Mb RAM // 255 = 2.9 Mb RAM // 1000 = 6.6 Mb RAM // 10_000 = 55.1 Mb RAM // 100_000 = 180.3 -> 434.4 Mb RAM
  14. //int i = 100_000; // freeze with 180.3 -> 434.4 Mb RAM .. ((
  15. while(i > 0){
  16. spawn(&test1_worker, i);
  17. i--;
  18. }
  19. }
  20. /*
  21. // 1 OS process, 10 threads
  22. > make run
  23. ./vtest2
  24. started worker = 8
  25. started worker = 7
  26. started worker = 9
  27. started worker = 6
  28. started worker = 1
  29. started worker = 10
  30. started worker = 5
  31. started worker = 3
  32. started worker = 2
  33. started worker = 4
  34. stopped worker = 8
  35. stopped worker = 9
  36. stopped worker = 7
  37. stopped worker = 10
  38. stopped worker = 6
  39. stopped worker = 1
  40. stopped worker = 4
  41. stopped worker = 3
  42. stopped worker = 5
  43. stopped worker = 2
  44. hello here!
  45. */