12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- // https://git.4dev.win/221V/vibed_test2/src/4d2bd29ff6d5199507146a14f0ce07d863c776f2/vtest2/source/app.d
- 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);
-
- while(true){
- //Thread.sleep(dur!"seconds"(120));
-
- //Thread.sleep(dur!"seconds"(3));
-
- auto v20 = fact(20);
- //writeln("worker = ", n, " fact 20 = ", v20); // this is sync lock ((
- }
-
- 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
- //int i = 30_000;
- int i = 10; // 11 threads - OS processes
- //int i = 35_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
- */
|