Microsoft DirectX 8.0 (C++) |
Microsoft® DirectPlay® and DirectPlay Voice both require you to implement and register several callback functions to handle the events fired by DirectPlay. DirectPlay is multithreaded and will fire multiple events concurrently. It is possible that your application will receive multiple overlapping callbacks.
DirectPlay maintains a thread pool to service callback indications, and your callback is invoked on a thread from the pool of threads maintained by DirectPlay. The size of this thread pool is configurable on a per process basis in Microsoft Windows 2000. Also, DirectPlay will use I/O completion ports when running on Windows 2000. I/O completion ports is an advanced topic beyond the scope of this document, and it is recommended that you look in the Microsoft Developer Network documents or in one of the Win32 multithreading references currently available.
In order to correctly and reliably access data in DirectPlay callbacks, you are required to implement a method of multithreading synchronization. This is known as making your callback re-entrant or threadsafe.
The Microsoft Windows family of operating systems currently offers three methods of synchronizing data in multithreaded environments:
The DirectPlay voice samples that ship with the DirectX 8.0 SDK demonstrate synchronization using Critical Section Objects. If you wish to implement a Mutex or Semaphore Object, these topics are discussed in the Microsoft Platform SDK as well as in many reference books. Implementing any of these synchronization methods requires an expert knowledge level in these areas due of the level of complexity and difficulty in debugging should any issues arise.
The DirectPlay threading model is optimized for maximum efficiency and there are no thread context switches during "send" operations and during "indication" messages, including receive messages.
This section discusses DirectPlay Networking Callbacks.
See Implementing a Callback Function in DirectPlay and DirectPlay Voice for more information.