Threads pause during DeviceIoControl()
Posted: Wed Nov 13, 2024 7:21 am
My GUI application works with SCSI devices using SCSI passthrough (SPTI) in non-overlapped mode, i.e. the call looks like this:
The DeviceIoControl() call is made by the main thread and my application has a sub thread running to service the GUI at regular intervals. However, whenever the main thread is waiting for DeviceIoControl() to return, my GUI sub thread also pauses.
I'm working with relatively slow SCSI tape drives and some SCSI operations (like load / unload medium and rewind) can take 30s or more to complete, during which the main GUI often goes into the 'not responding' state, until the command completes, which I want to avoid.
I've tested having a sub thread to handle the SCSI operations but this makes no difference - the main and GUI sub threads in my application still pause until the DeviceIoControl() call made by the SCSI sub thread, returns.
Is this expected behaviour in Windows 10/11? Is there a better way to code this, other than modifying the SCSI CDB for IMMED=1 or using overlapped mode to reduce the time spent in DeviceIoControl() ? Thanks.
Code: Select all
; Make the call
lResult=DeviceIoControl_(*SCSI\hDevice, ; handle to the SPTI device
#IOCTL_SCSI_PASS_THROUGH_DIRECT, ; [in] dwControlCode
*SCSI\SPTDWS\SPTD, ; [in] pointer to the SPTD structure
SizeOf(SCSI_PASS_THROUGH_DIRECT), ; [in] the size of the SPTD structure
*SCSI\SPTDWS\SPTD, ; [out] pointer to the output SPTDWS structure (overwrites input SPTD)
SizeOf(SCSI_PASS_THROUGH_DIRECT_WITH_SENSE),; the size of the SPTDWS structure (to include Sense buffer at specified offset)
@lBytesRet, ; [out] pointer to a variable that received the size of data returned
#Null) ; [N/A] not used for non-overlapped operations
I'm working with relatively slow SCSI tape drives and some SCSI operations (like load / unload medium and rewind) can take 30s or more to complete, during which the main GUI often goes into the 'not responding' state, until the command completes, which I want to avoid.
I've tested having a sub thread to handle the SCSI operations but this makes no difference - the main and GUI sub threads in my application still pause until the DeviceIoControl() call made by the SCSI sub thread, returns.
Is this expected behaviour in Windows 10/11? Is there a better way to code this, other than modifying the SCSI CDB for IMMED=1 or using overlapped mode to reduce the time spent in DeviceIoControl() ? Thanks.