Multiple Threads and VixDiskLib
VDDK supports concurrent I/O to multiple virtual disks, with certain limitations:
- VixDiskLib_InitEx() or VixDiskLib_Init() should be called once per process, from the main thread.
- In the VixDiskLib_InitEx() or VixDiskLib_Init() function call, do not specify logging callbacks as NULL. This causes VixDiskLib to provide its default logging functions, which are not thread safe. If you are using VDDK in a multithreaded environment, you must provide your own thread-safe log functions.
- When you call
VixDiskLib_Open() and
VixDiskLib_Close(), VDDK
initializes and uninitializes a number of libraries, some of which do not work
if called from multiple threads. For example, this fails:
Thread 1: VixDiskLib_Open ...... VixDiskLib_Close Thread 2: ................................... VixDiskLib_Open ...... VixDiskLib_Close
The workaround is to use one designated thread to do all opens and closes, and to have other worker threads doing reads and writes. This diagram shows concurrent reads on two separate disk handles. Concurrent reads on the same disk handles are not allowed.
Open/Close Thread: VixDiskLib_Open ...... VixDiskLib_Open ...... VixDiskLib_Close ...... VixDiskLib_Close ...... (handle1) (handle2) (handle1) (handle2) I/O Thread 1: (owns handle1) VixDiskLib_Read ... VixDiskLib_Read ... I/O Thread 2: (owns handle2) VixDiskLib_Read ... VixDiskLib_Read ...