Some sample code for multithreaded server programming under Windows NT
by
Dr. Thomas Becker
tmbecker@compuserve.com
NamedPipeArray.h
NamedPipeArray.htm
Source and documentation of a class template that wraps an array
of Win32 named pipe instances.
PassiveQueue.h
PassiveQueue.htm
Source and documentation of a class template that provides a
simple thread-safe FIFO queue.
ActiveQueueWithTimeout.h
ActiveQueueWithTimeout.htm
Source and documentation of a class template that provides a
thread-safe FIFO queue with variable timeout.
MTServerV1 uses the CNamedPipeArray class to communicate with clients and the CPassiveQueue class to queue them. A fixed number of working threads picks clients from the queue. The server reads one byte from the client end of the pipe. The default action is to send back the index of the pipe and the thread that served the client. Some characters cause special action; run the client program to see what these are.
The number of pipe instances, the length of the queue, and the number of worker threads can be set with preprocessor definitions at the beginning of file MTServerV1.cpp.
MTServerV2 uses the CNamedPipeArray class to communicate with clients and the CActiveQueueWithTimeout class to queue them. A fixed number of working threads picks clients from the queue. The server reads one byte from the client end of the pipe. The default action is to send back the index of the pipe and the thread that served the client. Some characters cause special action; run the client program to see what these are.
The number of pipe instances, the length of the queue, the number of worker threads, and the timeout value for all clients can be set with preprocessor definitions at the beginning of file MTServerV2.cpp.
If you build the sample program MTServerV2 using your own workspace rather than the one provided here, then make sure you set _WIN32_WINNT to 0x0400. See the description of the Timers directory below for an explanation.
By default, the program connects to the server and then prompts the user to enter a character. The effect is described in the prompt.
If you compile the program with the preprocessor constant RAPID_FIRE defined, the program will make connections to the server and send ASCII 0 without user interaction. This can be used to stress-test the server.
Which of the two timer classes is used by CActiveQueueWithTimeout depends on the value of the preprocessor constant _WIN32_WINNT. If it is greater than or equal to 0x0400, then the real Win32 waitable timer is used.
If you build the sample program MTServerV2 using your own workspace rather than the one provided here (MTServerV2.dsw in the directory MTServerV2), then make sure you set _WIN32_WINNT to 0x0400. Else, you will be using the waitable timer substitute rather than the real thing.