test1.d 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // https://git.4dev.win/221V/vibed_test2/src/4d2bd29ff6d5199507146a14f0ce07d863c776f2/vtest2/source/app.d
  2. alias uint8 = ubyte;
  3. alias uint64 = ulong;
  4. import std.stdio;
  5. import std.concurrency : spawn;
  6. import core.time : Duration, dur;
  7. import core.thread : Thread;
  8. uint64 fact(uint64 n){
  9. return fact(n, 1);
  10. }
  11. uint64 fact(uint64 n, uint64 a){
  12. if(n == 0){
  13. return a;
  14. }else{
  15. return fact(n - 1, n * a);
  16. }
  17. }
  18. //void test1_worker(uint8 n){
  19. void test1_worker(int n){
  20. writeln("started worker = ", n);
  21. while(true){
  22. //Thread.sleep(dur!"seconds"(120));
  23. //Thread.sleep(dur!"seconds"(3));
  24. auto v20 = fact(20);
  25. //writeln("worker = ", n, " fact 20 = ", v20); // this is sync lock ((
  26. }
  27. Thread.sleep(dur!"seconds"(3));
  28. writeln("stopped worker = ", n);
  29. }
  30. void test1_spawner(){
  31. //uint8 i = 10; // 10 = 1.8 Mb RAM // 255 = 2.9 Mb RAM // 1000 = 6.1 Mb RAM // 10_000 = 47.9 Mb RAM // 100_000 = 180.3 -> 434.4 Mb RAM ,, 161.8 -> 607.7 Mb RAM
  32. //int i = 100_000; // fails
  33. //int i = 30_000;
  34. int i = 10; // 11 threads - OS processes
  35. //int i = 35_000; // fails
  36. /**/
  37. while(i > 0){
  38. spawn(&test1_worker, i);
  39. i--;
  40. }
  41. /**/
  42. }
  43. /*
  44. > make run
  45. ./vtest2
  46. ...
  47. // core.thread.threadbase.ThreadError@core/thread/threadbase.d(1297): Error creating thread
  48. */