MATLAB: Does using the S-function with Real-Time Windows Target cause Windows to crash

%sallocatefunctionmemorymxfreemxmallocrealtimewindows

I have created a C-MEX S-function which performs some memory management in the mdlOutputs function. I can use this S-function without error in normal simulation mode, and I can also successfully generate code for the GRT target. When I build the model for the Real-Time Windows Target, it does not report any errors, and it connects to the Real-Time Windows kernel without error. However, when I start the simulation, Windows crashes to a blue screen reporting "DRIVER_IRQL_NOT_LESS_THAN_OR_EQUAL".

Best Answer

This change has been incorporated into the documentation in Release 14 Service Pack 3 (R14SP3). For previous releases, read below for any additional information:
The ability to manage memory in the mdlOutputs method of a C-MEX S-function is not currently available for Real-Time Windows Target. In order for the simulation to run in real time, mdlOutputs must be run at the highest priority available in the system. This priority is higher than the memory manager. The error is generated because the memory manager cannot respond to the request to allocate memory. Also, the memory manager is not guaranteed to complete its task in a given time, unlike real-time code, which must complete its tasks in each time step.
In order to work with the Real-Time Windows Target, memory management must occur before the simulation starts. The recommended practice is to perform memory management in mdlInitializeSizes, but in some cases mdlStart is also an appropriate place to allocate memory.