g***@hotmail.com
20 years ago
Hi, i have recently been working with C# async IO. I have now moved
back to C++ to write some server software.
I quickly realised the C#/.NET IO mechanism is extremely efficient
compared to my old ways in C++ where i was creating a seperate thread
for each client.
I would like to create a similair architecture with my new software,
and have been playing about with IO completion ports. They seem to be
working, but i would appreciate clarification on a few points.
After creating my worker threads and completion port, I loop on
GetQueuedCompletionStatus() in my worker threads (i have been using
example 6-4 from "Multithreading Applications in Win32").
I have noticed if i put a blocking sleep inside the worker thread loop
(for testing only of course!), only one thread is released to service a
client at any one time... now this is fine for me as i dont have to
deal with async issues per client when buffering the read data for
instance.
However in the book "Multithreading Applications in Win32" it mentions
the "completion port will notice that Thread 1 blocked on disk I/O and
will release Thread 2 to bring the count of currently running threads
back up to the requested number".
Perhaps i am getting confused, but from my tests it seems threads are
only 'released' to service IO completion one at a time for individual
handles, yet IO completions will be serviced in parallel (waking
threads as necessary) for seperate handles?
Sorry for the somewhat confusing explanation, please let me know if
parts dont make sense so i can try to clarify. Thanks in advance,
Chris
back to C++ to write some server software.
I quickly realised the C#/.NET IO mechanism is extremely efficient
compared to my old ways in C++ where i was creating a seperate thread
for each client.
I would like to create a similair architecture with my new software,
and have been playing about with IO completion ports. They seem to be
working, but i would appreciate clarification on a few points.
After creating my worker threads and completion port, I loop on
GetQueuedCompletionStatus() in my worker threads (i have been using
example 6-4 from "Multithreading Applications in Win32").
I have noticed if i put a blocking sleep inside the worker thread loop
(for testing only of course!), only one thread is released to service a
client at any one time... now this is fine for me as i dont have to
deal with async issues per client when buffering the read data for
instance.
However in the book "Multithreading Applications in Win32" it mentions
the "completion port will notice that Thread 1 blocked on disk I/O and
will release Thread 2 to bring the count of currently running threads
back up to the requested number".
Perhaps i am getting confused, but from my tests it seems threads are
only 'released' to service IO completion one at a time for individual
handles, yet IO completions will be serviced in parallel (waking
threads as necessary) for seperate handles?
Sorry for the somewhat confusing explanation, please let me know if
parts dont make sense so i can try to clarify. Thanks in advance,
Chris