Click here to Skip to main content
15,889,096 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: IOCP server [modified] Pin
Jhony george28-Nov-07 1:57
Jhony george28-Nov-07 1:57 
AnswerRe: IOCP server Pin
Cedric Moonen28-Nov-07 2:18
Cedric Moonen28-Nov-07 2:18 
GeneralRe: IOCP server Pin
Jhony george28-Nov-07 2:26
Jhony george28-Nov-07 2:26 
GeneralRe: IOCP server Pin
Mark Salsbery28-Nov-07 5:32
Mark Salsbery28-Nov-07 5:32 
GeneralRe: IOCP server Pin
Mike Dimmick28-Nov-07 5:55
Mike Dimmick28-Nov-07 5:55 
GeneralRe: IOCP server Pin
Mark Salsbery28-Nov-07 6:08
Mark Salsbery28-Nov-07 6:08 
AnswerRe: IOCP server Pin
Mark Salsbery28-Nov-07 5:26
Mark Salsbery28-Nov-07 5:26 
AnswerRe: IOCP server Pin
Mike Dimmick28-Nov-07 5:43
Mike Dimmick28-Nov-07 5:43 
When using I/O completion ports you are supposed to have a much smaller pool of threads. The operating system only runs as many threads concurrently as are necessary to keep the CPUs busy. I haven't got space here to explain it fully, you should see "Programming Server-Side Applications for Windows" for more information, but basically when a thread calls GetQueuedCompletionStatus, it will block. When an I/O request completes, and the number of threads already running is less than the number of CPUs, Windows will unblock the first waiting thread. Threads that complete their request and call GetQueuedCompletionStatus again go back to the head of the queue (this should keep the thread's data variables 'hot' in the processor cache).

The magic is this: if a thread that is associated with a completion port blocks for some other reason, Windows looks to see if there are now fewer threads than the number of CPUs running, and if so, it releases another one. On the whole, this keeps the number of threads down and therefore the number of context switches between runnable threads minimized (which is time spent unnecessarily switching between threads that could otherwise have been used for useful work).

Each new thread requires its own stack. The actual stack size reserved depends on compiler switches, by default, 1MB per thread. Multiplying up you can see that 3,969 threads is about 4GB of reserve. You're blowing your entire virtual address space on thread stacks. That's the practical limit of how many threads you can create in one process.


DoEvents: Generating unexpected recursion since 1991

QuestionLPBITMAPINFOHEADER Pin
keyto28-Nov-07 0:49
keyto28-Nov-07 0:49 
AnswerRe: LPBITMAPINFOHEADER Pin
CPallini28-Nov-07 0:57
mveCPallini28-Nov-07 0:57 
AnswerRe: LPBITMAPINFOHEADER Pin
David Crow28-Nov-07 3:03
David Crow28-Nov-07 3:03 
QuestionHow to use VC++ Unit Test project to test C++ project Pin
lchild38528-Nov-07 0:09
lchild38528-Nov-07 0:09 
QuestionVC 2005 compiler error Pin
neha.agarwal2728-Nov-07 0:01
neha.agarwal2728-Nov-07 0:01 
AnswerRe: VC 2005 compiler error Pin
toxcct28-Nov-07 0:21
toxcct28-Nov-07 0:21 
GeneralRe: VC 2005 compiler error Pin
neha.agarwal2728-Nov-07 0:31
neha.agarwal2728-Nov-07 0:31 
GeneralRe: VC 2005 compiler error Pin
CPallini28-Nov-07 0:45
mveCPallini28-Nov-07 0:45 
GeneralRe: VC 2005 compiler error Pin
neha.agarwal2728-Nov-07 1:00
neha.agarwal2728-Nov-07 1:00 
GeneralRe: VC 2005 compiler error Pin
David Crow29-Nov-07 2:45
David Crow29-Nov-07 2:45 
GeneralI know... Pin
CPallini29-Nov-07 3:07
mveCPallini29-Nov-07 3:07 
GeneralRe: VC 2005 compiler error Pin
toxcct28-Nov-07 1:34
toxcct28-Nov-07 1:34 
GeneralRe: VC 2005 compiler error Pin
neha.agarwal2728-Nov-07 1:38
neha.agarwal2728-Nov-07 1:38 
GeneralRe: VC 2005 compiler error Pin
toxcct28-Nov-07 1:40
toxcct28-Nov-07 1:40 
GeneralRe: VC 2005 compiler error Pin
Cedric Moonen28-Nov-07 1:47
Cedric Moonen28-Nov-07 1:47 
GeneralRe: VC 2005 compiler error Pin
neha.agarwal2728-Nov-07 17:36
neha.agarwal2728-Nov-07 17:36 
GeneralRe: VC 2005 compiler error Pin
David Crow29-Nov-07 2:51
David Crow29-Nov-07 2:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.