1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- // todo test https://dlang.org/phobos/std_parallelism.html
- alias uint8 = ubyte;
- alias uint64 = ulong;
- import std.stdio;
- import std.concurrency : spawn;
- import core.time : Duration, dur;
- import core.thread : Thread;
- uint64 fact(uint64 n){
- return fact(n, 1);
- }
- uint64 fact(uint64 n, uint64 a){
- if(n == 0){
- return a;
- }else{
- return fact(n - 1, n * a);
- }
- }
- //void test1_worker(uint8 n){
- void test1_worker(int n){
- writeln("started worker = ", n);
-
- //Thread.sleep(dur!"seconds"(120));
- Thread.sleep(dur!"seconds"(3));
-
- auto v120 = fact(120);
- writeln("worker = ", n, " fact 120 = ", v120);
-
- Thread.sleep(dur!"seconds"(3));
-
- writeln("stopped worker = ", n);
- }
- void test1_spawner(){
- //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
- int i = 100_000; // fails
-
- /**/
- while(i > 0){
- spawn(&test1_worker, i);
-
- i--;
- }
- /**/
-
- }
- /*
- > make run
- ./vtest2
- ...
- // core.thread.threadbase.ThreadError@core/thread/threadbase.d(1297): Error creating thread
- */
|