winapivideoms-media-foundationdirect3d11

Should I use `semaphore` or `ID3D10Multithread ` to solve the corrution of the memory?


D3D11 CORRUPTION: ID3D11DeviceContext::Unmap: Two threads were found to be executing functions associated with the same Device[Context] at the same time. This will cause corruption of memory. Appropriate thread synchronization needs to occur external to the Direct3D API (or through the ID3D10Multithread interface). 3628 and 17364 are the implicated thread ids. [ MISCELLANEOUS CORRUPTION #28: CORRUPTED_MULTITHREADING]

I use IMFTransform in thread A and thread B and thread C and they always throw the exception of CORRUPTION

if I use ID3D10Multithread to enable multi-thread will it be slower than semaphore?


Solution

  • When you are using D3D11 device in Media Foundation scenarios, you would typically have to use threading protection ID3D11Multithread. Media Foundation design is such that device manager is shared between primitives, and those are using the device from random RTWQ threads, not necessarily serializing device usage via the manager. In the end of the day you don't know if the device is used concurrently on a worker thread, hence the need in protection.