Pay as you go is really going to make a difference

Steven Schveighoffer schveiguy at
Sun Jan 26 00:18:49 UTC 2020

On 1/25/20 6:41 PM, norm wrote:
> On Saturday, 25 January 2020 at 16:07:24 UTC, Steven Schveighoffer wrote:
>> On 1/24/20 5:20 PM, Gregor Mückl wrote:
>>> So there's a couple of calls that should be fairly fast (clock_getres 
>>> etc.). Why does the runtime need to read /proc/self/maps, though?
>> This is great stuff, thanks!
>> Note that /proc/self/maps appears nowhere in phobos or druntime. So 
>> I'm assuming that's some other function that's doing it (maybe in libc?)
>> The clock_getres calls are so you can use core.time.MonoTime. rt_init 
>> initializes those so they can be used early in the process. I would 
>> assume those are really fast, as they are constants in the kernel.
> I was curious so I ran a quick strace hello world experiment using only 
> printf, not writeln, compiled with D (DMD), C++ and C (gcc and clang). 
> Only the D binary opens /proc/self/maps. Running `strace dmd --version` 
> also opens /proc/self/maps, but I guess that makes sense since the 
> compiler itself is now written in D.

Yeah, it's not being opened directly by druntime, but looks like 
pthread_getattr_np (man strace -k is useful!):

openat(AT_FDCWD, "/proc/self/maps", O_RDONLY|O_CLOEXEC) = 3
  > /lib/x86_64-linux-gnu/ [0x10fdb1]
  > /lib/x86_64-linux-gnu/ [0x8cc3d]
  > /lib/x86_64-linux-gnu/ [0x7eeaa]
  > /lib/x86_64-linux-gnu/ 
  > /mnt/hgfs/Documents/testd/teststrace(thread_init+0x250) [0x50d98]
  > /mnt/hgfs/Documents/testd/teststrace(rt_init+0x4c) [0x3f880]
  > /mnt/hgfs/Documents/testd/teststrace(_d_run_main2+0x22e) [0x3c462]
  > /mnt/hgfs/Documents/testd/teststrace(_d_run_main+0xbe) [0x3c21e]
  > /mnt/hgfs/Documents/testd/teststrace(main+0x22) [0x3c136]
  > /lib/x86_64-linux-gnu/ [0x21b97]
  > /mnt/hgfs/Documents/testd/teststrace(_start+0x2a) [0x3c01a]

So it's something to do with thread_init calling pthread_getattr_np. I 
don't see a direct call in there, so probably it's inlined or tail-calling.

And is that really using fopen? my goodness..

I'm not sure we can pay-as-you-go the low-level thread support. And we 
can't do anything about how pthreads use the OS to implement their 


More information about the Digitalmars-d mailing list