test1.d 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // todo test https://dlang.org/phobos/std_parallelism.html
  2. // https://git.4dev.win/221V/vibed_test2/src/4d2bd29ff6d5199507146a14f0ce07d863c776f2/vtest2/source/app.d
  3. // https://chat.qwen.ai/c/5cfd2bc3-66eb-4ca5-a2cd-7126e99e4dc4
  4. // https://vibed.org/api/vibe.core.channel/
  5. alias uint8 = ubyte;
  6. alias uint64 = ulong;
  7. import std.stdio;
  8. import std.concurrency : spawn;
  9. import core.time : Duration, dur;
  10. import core.thread : Thread;
  11. uint64 fact(uint64 n){
  12. return fact(n, 1);
  13. }
  14. uint64 fact(uint64 n, uint64 a){
  15. if(n == 0){
  16. return a;
  17. }else{
  18. return fact(n - 1, n * a);
  19. }
  20. }
  21. //void test1_worker(uint8 n){
  22. void test1_worker(int n){
  23. writeln("started worker = ", n);
  24. while(true){
  25. //Thread.sleep(dur!"seconds"(120));
  26. Thread.sleep(dur!"seconds"(3));
  27. auto v20 = fact(20);
  28. writeln("worker = ", n, " fact 20 = ", v20); // this is sync lock ((
  29. }
  30. Thread.sleep(dur!"seconds"(3));
  31. writeln("stopped worker = ", n);
  32. }
  33. void test1_spawner(){
  34. //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
  35. //int i = 100_000; // fails
  36. int i = 30_000;
  37. //int i = 35_000; // fails
  38. /**/
  39. while(i > 0){
  40. spawn(&test1_worker, i);
  41. i--;
  42. }
  43. /**/
  44. }
  45. /*
  46. > make run
  47. ./vtest2
  48. ...
  49. // core.thread.threadbase.ThreadError@core/thread/threadbase.d(1297): Error creating thread
  50. */