Asynchronous functions were added to Winsock to make sockets friendlier to the GUI programmer. When an application issues an asynchronous Winsock call, Winsock starts processing the call and immediately returns to the caller. When the call completes, Winsock posts a message to the application's message queue to inform the application of the results of the function.
For the OS/2 implementation of Winsock, asynchronous calls are handled similarly to the way blocking hooks are handled. Each call to an asynchronous Winsock function causes a secondary thread to issue the socket call. The original thread then returns to the application. When the socket call returns, the secondary thread posts a message to the appropriate message queue.
To avoid creating and terminating many threads, the asynchronous calls maintain a small pool of threads that are dedicated to servicing asynchronous calls. The threads are created as needed and are not terminated until the application ends. When the application issues an asynchronous call, Winsock determines if there is a free thread in the pool. If a free thread exists, Winsock uses it to service the call. If there is not a free thread in the pool, Winsock checks to see if the maximum number of threads that can fit in the pool has been started. If the maximum number of threads has not been started, Winsock starts a new thread, adds it to the pool, and has the new thread service the socket call.
If no free threads are in the pool and the pool is filled to capacity, Winsock starts a new thread to service the call. After the call completes and the message has been posted, the new thread terminates.