3 ms·
This depends on thread implementation and how much is allocated for the stack. Java will by default allocate 1MB, you can change that if you know what are you d
by Chyzwar 9y ago
This depends on thread implementation and how much is allocated for the stack. Java will by default allocate 1MB, you can change that if you know what are you doing.
I know that you can have millions of M:N/green threads but these are different. In any case, you need to compete for memory and CPU time to execute.
Since not many people are programming in Haskell and BEAM languages my simplifications still hold.
- masklinn 9y ago> This depends on thread implementation and how much is allocated for the stack. Java will by default allocate 1MB, you can change that if you know what are you doing. Isn't that vmem? Unless it also writes to the entirety of that 1MB before starting the thread, it's not actually committed by default on most unices.
- vbezhenar 9y agoI'm talking about real threads, not green threads and I used Java for my quick test. Here's code, you can run it yourself. masklinn is correct about virtual memory, every sane OS will only use few kilobytes for short stacks. public class Test { volatile static boolean stop = false; static AtomicInteger counter = new AtomicInteger(); public static void main(String[] args) throws InterruptedException { Thread[] threads = new Thread[100000]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(() -> { counter.incrementAndGet(); while (!stop) { try { Thread.sleep(1000); } catch (InterruptedException ignored) { } } }); } for (Thread thread : threads) { thread.start(); } while (counter.get() < threads.length) { Thread.sleep(1000); } System.out.println("Threads are running"); Thread.sleep(10000); stop = true; for (Thread thread : threads) { thread.join(); } } }