| Customize Help

Characteristics of a user-defined MIL function



Each user-defined MIL function consists of a master and a slave function. The master function provides the user interface and sets up the MIL function context for the new function. In the master function, you must allocate the function context for the new function, register the parameters declared by the master function as parameters of the user-defined MIL function, call the slave function, and, in the end, free the allocated MIL identifier of the function.

The slave function is a separate function that actually performs the required operations when the user-defined MIL function is called. The slave function must be implemented as a separate function because it can be executed remotely by a slave node in a Distributed MIL application. The only parameter that is passed to the slave function is the MIL identifier of the function context. The slave function uses this identifier to access the MIL function context and retrieve the parameters from the context using the MfuncParamValue() function. You can also make calls to other MIL functions from the slave function.

Note that to increase efficiency, parameter checking is not performed for user-defined MIL functions.

Remote and local functions

When allocating your function context using MfuncAlloc() in the master function, you must specify whether your user-defined MIL function will be executed on the master computer or the remote computer with M_LOCAL or M_REMOTE.

User-defined MIL functions allocated as M_LOCAL will be executed by the Host processor, whereas user-defined MIL functions allocated as M_REMOTE will be executed by a remote processor, if one is available.

Asynchronous and synchronous functions

When allocating your function context using MfuncAlloc() in the master function, you must specify whether your user-defined MIL function will run asynchronously or synchronously (M_ASYNCHRONOUS_FUNCTION or M_SYNCHRONOUS_FUNCTION) with respect to the calling thread.

User-defined MIL functions allocated to run asynchronously will return control to the calling thread immediately after being called. One advantage of running functions asynchronously is that they allow the master function to immediately proceed to the next statement, while the slave processor executes the slave function. Note that an asynchronous function can modify MIL buffers and parameters passed by reference, but cannot actually return a value. For more information on return values, see the Return values subsection of the Parameter registration and return values section later in this chapter.

Note that user-defined MIL functions allocated to run on the Host processor must be run synchronously and user-defined MIL functions allocated to run on the remote processor can be run asynchronously or synchronously.