Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coroutines with a growing stack in C

I want to use coroutines in C (Linux), but I don't want to waste lots of space for each one. I'm wondering about allocating the space for the stack with mmap() given MAP_GROWSDOWN, but I read somewhere that it was broken, do you know any more about this?

like image 364
dan_waterworth Avatar asked Nov 29 '25 01:11

dan_waterworth


1 Answers

but I don't want to waste lots of space for each one

Don't worry about it. Your coroutine can have a large stack but it will not cause any performance or resource problems unless the stack is actually used. The logical pages of memory will not be assigned physical pages until that point. And if it is used, well you needed it then didn't you?

Just use a decent sized stack and have done with it.

like image 64
Ben Avatar answered Nov 30 '25 14:11

Ben