News for hackers. Stuff that matters.
Re:Stack size invisibility in C and the effects on "portabil... by jeffbee on Tuesday September 28, 2021 @11:03AM (#28683619)
Managing your own pthread stacks can make thread more costly though, can't it? Use of pthread_set_stack requires stack_size at least PTHREAD_STACK_MIN which on glibc linux tends to be 16384, four times larger than the initial cost of a demand-paged stack map. I understand that on musl this is 2048, so that's nice.
Re:Stack size invisibility in C and the effects on "portabil... by titzer on Tuesday September 28, 2021 @11:08AM (#28683680)
Yeah, I think there would be some overhead, because it doesn't look like pthread_create allows specifying a stack segment. But I wouldn't be using pthread_create (or any C library for that matter), because Virgil goes all the way down to kernel; there is no C environment.

I only experimented briefly[1] with getting Virgil threads to run on Linux. You need to call SYS_clone, which forks a lightweight process (i.e. shares all virtual memory), and specify a stack segment. The segment in question would of course, be mapped by Virgil and not have MAP_GROWSDOWN, so it could be made robust to stack overflow along the lines above.

[1] https://github.com/titzer/virgil/blob/master/apps/Multi/Mult...