Previous in Contents Next in Contents

Multiple Threading

The Payment Selector supports single processes with multiple threads and multiple processes with one or more threads. During the Add, Modify, and Delete functions, mutexes in the Payment Selector permit only one thread at a time to modify data. Each component is required to share its data among both multiple threads within a single process and multiple processes. Modifications using one instance of the control must be reflected in all instances. The SDK sample uses shared global memory to implement this requirement. You must ensure that multiple instances of the Create function are thread safe.

The SDK sample uses the following elements to ensure thread safety:

The MFC CWinApp class captures and transforms the first thread into an MFC thread in the component data structure when the DLL is loaded. The SDK files thrdwrap.cpp and thrdchk.h create the necessary threading structures within MFC to make MFC thread safe within a single process, independent of the shared global data structure. The thrdwrap.cpp file, which includes the thrdwrap.h header file, implements a thread class and checks thread routines to ensure that MFC has the necessary information to perform thread-safe processes. The thrdchk.h header file defines the entry points to the current thread to check whether or not it exists.

Although the majority of multiple-thread and multiple-process support occurs in the Payment Selector, you must provide a mutex for the Create function to ensure that new instances of the component are created in a thread-safe manner.

To verify that your CPC supports multiple threading
  1. Start Internet Explorer version 3.0 or later.
  2. Open your local HTML page containing the Payment Selector control.
  3. On the File menu, click New Window to create a second copy of the control. The second copy of the control is run on a new thread within the original process.
  4. Test the second thread to verify multiple threading in the control.

Note  Do not modify the sample files thrdwrap.cpp and thrdchk.h, because these files support thread-safe processes in MFC.

See the Win32 Programmer's Reference for additional information on creating a mutex.


© 1997-2000 Microsoft Corporation. All rights reserved.