GDC - program runs in one thread, DMD - in 4 threads, why?
eugene
dee0xeed at gmail.com
Fri Sep 10 09:27:49 UTC 2021
Here is test program (which is using DList aggressively)
```d
import std.stdio : writeln;
import core.sys.posix.unistd : sleep;
//import std.container.dlist; // dmd (v2.097.2)
import std.container: DList; // gdc (4.9.2)
void main() {
auto list = DList!(int)();
int k;
while (true) {
// 1.sleep;
k.writeln;
list.insertBack(k);
list.insertBack(k);
list.removeFront();
list.removeFront();
k++;
}
}
```
When compiled with gdc, it runs in one thread:
@dexp ~ $ ps xH | grep [t]est
3823 pts/12 R+ 0:07 ./test
But when with dmd, program creates 3 additional threads:
@dexp ~ $ ps xH | grep [t]est
3839 pts/12 Rl+ 0:00 ./test
3839 pts/12 Sl+ 0:00 ./test
3839 pts/12 Sl+ 0:00 ./test
3839 pts/12 Sl+ 0:00 ./test
What are these extra threads for?
To work with list (which is strange)???
GC?
Something else?
Observations:
- without DList there is no extra-threads
- with sleep() there is also no extra-threads
So I think it is **very aggressive usage** of DList that causes
this.
Can this (really unwanted) behavior be disabled in DMD?
I do not want to have multiple threads,
a program (real program, not the test above) has to be
single-threaded.
system used:
@dexp ~ $ cat /etc/debian_version
8.11
More information about the Digitalmars-d-learn
mailing list