Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #87311

Re: Windows does overcommit stacks !

From Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups comp.lang.c++
Subject Re: Windows does overcommit stacks !
Date 2022-11-10 12:42 +0100
Organization A noiseless patient Spider
Message-ID <tkio2e$hqak$1@dont-email.me> (permalink)
References <tkhqdn$fho3$1@dont-email.me> <5194adaf-d276-4fdb-b422-55e4a6ed5d70n@googlegroups.com>

Show all headers | View raw


Am 10.11.2022 um 11:59 schrieb Michael S:

> FYI, unlike another popular OS, Windows *never* overcommits.

Try it out yourself:

#include <Windows.h>
#include <iostream>
#include <thread>
#include <vector>
#include <latch>
#include <memory>

using namespace std;

using XHANDLE = unique_ptr<void, decltype([]( void *h ) { h && h != 
INVALID_HANDLE_VALUE && CloseHandle( h ); })>;

int main()
{
	constexpr unsigned N_THREADS = 0x10000;
	vector<XHANDLE> threads;
	threads.reserve( N_THREADS );
	static latch latSync( N_THREADS );
	for( unsigned t = N_THREADS; t--; )
	{
		auto threadFn = []( LPVOID ) -> DWORD { latSync.arrive_and_wait(); 
return 0; };
		threads.emplace_back( CreateThread( nullptr, 0x1000000, threadFn, 
nullptr, 0, nullptr ) );
		if( !threads.back().get() )
			cout << "out of resources" << endl;
	}
	threads.resize( 0 );
	
}

This demo will allocate 2 ^ 16 threads with one terabyte of stack.
But as the stack on Windows is overcommitted, i.e. actually committed
when it is touched, this program won't crash !

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Windows does overcommit stacks ! Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-10 04:16 +0100
  Re: Windows does overcommit stacks ! yx ma <myxfxtstart@gmail.com> - 2022-11-09 23:32 -0800
  Re: Windows does overcommit stacks ! Michael S <already5chosen@yahoo.com> - 2022-11-10 02:59 -0800
    Re: Windows does overcommit stacks ! Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-10 12:42 +0100
      Re: Windows does overcommit stacks ! Michael S <already5chosen@yahoo.com> - 2022-11-10 04:34 -0800
        Re: Windows does overcommit stacks ! Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-10 14:08 +0100
          Re: Windows does overcommit stacks ! Öö Tiib <ootiib@hot.ee> - 2022-11-10 05:18 -0800
            Re: Windows does overcommit stacks ! Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-10 14:36 +0100
  Re: Windows does overcommit stacks ! Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-14 22:03 +0100
    Re: Windows does overcommit stacks ! Öö Tiib <ootiib@hot.ee> - 2022-11-15 04:09 -0800
      Re: Windows does overcommit stacks ! Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-15 14:23 +0100
        Re: Windows does overcommit stacks ! Michael S <already5chosen@yahoo.com> - 2022-11-15 06:23 -0800
          Re: Windows does overcommit stacks ! Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-15 16:39 +0100
  Re: Windows does overcommit stacks ! Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-20 18:45 +0100

csiph-web