test1.d 833 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. writeln("started worker = ", n);
  8. Thread.sleep(dur!"seconds"(120));
  9. writeln("stopped worker = ", n);
  10. }
  11. void test1_spawner(){
  12. uint8 i = 10;
  13. while(i > 0){
  14. spawn(&test1_worker, i);
  15. i--;
  16. }
  17. }
  18. /*
  19. // 1 OS process, 10 threads
  20. > make run
  21. ./vtest2
  22. started worker = 8
  23. started worker = 7
  24. started worker = 9
  25. started worker = 6
  26. started worker = 1
  27. started worker = 10
  28. started worker = 5
  29. started worker = 3
  30. started worker = 2
  31. started worker = 4
  32. stopped worker = 8
  33. stopped worker = 9
  34. stopped worker = 7
  35. stopped worker = 10
  36. stopped worker = 6
  37. stopped worker = 1
  38. stopped worker = 4
  39. stopped worker = 3
  40. stopped worker = 5
  41. stopped worker = 2
  42. hello here!
  43. */