5 ms·
Your point is correct but your magnitudes are off. IIRC, a thread takes up ~32kB or so worth of data in pthreads/Linux, or at least... somewhere around there.
by dragontamer 4y ago
Your point is correct but your magnitudes are off.
IIRC, a thread takes up ~32kB or so worth of data in pthreads/Linux, or at least... somewhere around there. So on a rather cheap server with 64GB of RAM, you can easily fit 1-million threads. More expensive servers have 512GB, 1TB or more RAM and can easily handle this kind of load.
Of course, coroutines are even smaller/more efficient and can go into 10-million, 100-million or higher.
- Matheus28 4y agoA thread on Windows is MUCH heavier than Linux. 1 MB stack from what I remember plus takes a lot longer to create.
- dragontamer 4y agodwStackSize can be set as low as 64kB though. So if you're in the habit of making millions-of-threads, maybe make them smaller on Windows? It does default to 1MB, but these sorts of things are configurable.
- klabb3 4y agoA bigger issue is creating and destroying threads, which can be costly if you don’t do a lot of work per each. Of course, people have worked around this problem for ages with thread pools, but then you’re already breaking up ownership, code flow and screwing up the stack for debugging and panicking. So something like coroutines or green threads is still motivated, it is just extremely different across languages and is almost always a leaky abstraction.