Click here to Skip to main content
15,902,189 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCapture Video from tv Tunner card Pin
Anonymous13-May-04 1:03
Anonymous13-May-04 1:03 
GeneralRe: Capture Video from tv Tunner card Pin
marcosvpp13-May-04 5:00
marcosvpp13-May-04 5:00 
GeneralESP error calling DLL exported function... Pin
Chris Ulliott13-May-04 0:54
Chris Ulliott13-May-04 0:54 
GeneralRe: ESP error calling DLL exported function... Pin
Justin Cooke13-May-04 4:19
Justin Cooke13-May-04 4:19 
GeneralRe: ESP error calling DLL exported function... Pin
bikram singh13-May-04 5:13
bikram singh13-May-04 5:13 
GeneralDrawThemeText Pin
Steve Thresher13-May-04 0:53
Steve Thresher13-May-04 0:53 
GeneralNetwork I/O models Pin
Rickard Andersson2012-May-04 23:51
Rickard Andersson2012-May-04 23:51 
GeneralRe: Network I/O models Pin
Mike Dimmick13-May-04 3:27
Mike Dimmick13-May-04 3:27 
Asynchronous is very difficult to program. You really have to split up your operations into various states to process as different bits of I/O complete. Typically you'd use asynchronous I/Os to get the best out of a thread-pooled server - you can have more I/O pending than you have threads, and you can perform part of a second client's request while waiting for I/O for the first to complete.

For best performance, you want to have a limited-size pool of threads, rather than one thread per client, for several reasons. Firstly there's overhead in creating and cleaning up threads. Secondly, each thread requires its own stack and possibly its own thread-local resources, which use up memory that you could be using for other things. Thirdly, the more threads there are which can run at any given time, the more time the OS spends switching between threads and the less actually doing work. The ideal is to have only one runnable thread per CPU. SQL Server uses this model (see Inside the User Mode Scheduler[^]).

Writing your code this way can give you the maximum potential performance, but it's hard.

Synchronous I/O is much easier: you simply write the code to perform the required steps in the required order. But you typically need more threads to achieve the same goal; if a thread is blocked waiting for I/O to serve one client, it can't serve another.

Synchronisation is an issue whether you're using asynchronous or synchronous I/O, so long as you're using multiple threads that may access the same shared data. It's a fact of life in a multithreaded program. It doesn't affect your choice of sync or async I/O. Locking reduces your concurrency, sure, if two threads contend on the same shared data. You can potentially improve this by increasing the granularity of your locks - locking less data, and holding locks for less time.

Windows provides the I/O completion port facility for simplifying and improving thread pooling. Threads and I/O handles can be associated with a particular completion port. Handles are associated by calling CreateIoCompletionPort; threads call GetQueuedCompletionStatus to block waiting for an I/O (on any of the handles associated with the port) to complete. So far, so simple. The twist is that the completion port enforces the maximum concurrency level - it will only unblock threads up to a specified number of threads running concurrently. What's more, if a thread belonging to the port is blocked for any reason, the completion port will release another if a completed I/O is waiting to be processed. This does mean that the number of runnable threads will typically be higher than the ideal one-per-processor.

Finally, to improve processor cache locality, the port releases threads in Last-In-First-Out order - the thread that handles a completed I/O is the last one which called GetQueuedCompletionStatus. These facilities have been present since NT 3.5. They're quite complex, however, for general thread pooling. For that, Windows 2000 also offers the QueueUserWorkItem API.

I suggest reading Programming Server-Side Applications for Windows[^] by Jeffrey Richter.

Stability. What an interesting concept. -- Chris Maunder
GeneralInstead a dialog I want to appear 3 buttons Pin
Filomela12-May-04 23:30
Filomela12-May-04 23:30 
GeneralRe: Instead a dialog I want to appear 3 buttons Pin
nguyenvhn13-May-04 1:50
nguyenvhn13-May-04 1:50 
GeneralRe: Instead a dialog I want to appear 3 buttons Pin
Filomela13-May-04 21:42
Filomela13-May-04 21:42 
GeneralRe: Instead a dialog I want to appear 3 buttons Pin
nguyenvhn13-May-04 22:41
nguyenvhn13-May-04 22:41 
GeneralTerminate a Named Program Pin
sweep12312-May-04 23:27
sweep12312-May-04 23:27 
GeneralRe: Terminate a Named Program Pin
Milton Karimbekallil12-May-04 23:56
Milton Karimbekallil12-May-04 23:56 
GeneralRe: Terminate a Named Program Pin
sweep12313-May-04 2:51
sweep12313-May-04 2:51 
GeneralRe: Terminate a Named Program Pin
jmkhael13-May-04 4:55
jmkhael13-May-04 4:55 
GeneralRe: Terminate a Named Program Pin
sweep12313-May-04 5:57
sweep12313-May-04 5:57 
GeneralKeeping variables in memory Pin
V.12-May-04 23:14
professionalV.12-May-04 23:14 
GeneralRe: Keeping variables in memory Pin
jmkhael13-May-04 2:22
jmkhael13-May-04 2:22 
GeneralRe: Keeping variables in memory Pin
Joe Woodbury13-May-04 9:15
professionalJoe Woodbury13-May-04 9:15 
Generalmessy function that calculates values Pin
bhangie12-May-04 22:40
bhangie12-May-04 22:40 
GeneralRe: messy function that calculates values Pin
toxcct12-May-04 22:56
toxcct12-May-04 22:56 
GeneralRe: messy function that calculates values Pin
WoutL12-May-04 23:11
WoutL12-May-04 23:11 
GeneralRe: messy function that calculates values Pin
Maximilien13-May-04 2:08
Maximilien13-May-04 2:08 
GeneralRe: messy function that calculates values Pin
David Crow13-May-04 5:30
David Crow13-May-04 5:30 

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.