OpenersNotesSection(Spacer1)Details

Some MathLink API calls will block until data is available to read or space is available for writing. If an application needs to perform other useful processing during that blocking time, the application can install a yield function for the link and MathLink will automatically make calls to the yield function while it blocks.

To back out of a blocked read or write, the yield function should return a nonzero value.

MLSetYieldFunction() will return 0 in the event of an error, and a nonzero value if the function succeeds.

On Windows the MLYieldFunctionObject uses the WINAPI calling convention.

Use (NonWLLink[MLError(), paclet:ref/c/MLError]) to retrieve the error code if MLSetYieldFunction() fails.

MLSetYieldFunction() is declared in the MathLink header file (RefLink[mathlink.h, paclet:ref/file/mathlink.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

#include "mathlink.h"

#if UNIX_MATHLINK
#	define CALLING_CONVENTION
#elif WINDOWS_MATHLINK
#	define CALLING_CONVENTION WINAPI
#endif

int CALLING_CONVENTION AppYieldFunction(MLINK lp, MLYieldParameters yp)
{
	/* ... */
	return 0;
}

int main(int argc, char **argv)
{
	MLENV env;
	MLINK link;
	int error;

	env = MLInitialize((MLEnvironmentParameter)0);
	if(env == (MLENV)0)
		{ /* unable to initialize MathLink environment */ }

	link = MLOpenArgcArgv(env, argv, argv + argc, &error);
	if(link == (MLINK)0 || error != MLEOK)
		{ /* unable to create the link */ }

	if(! MLSetYieldFunction(link, AppYieldFunction))
		{ /* unable to set the yield function for link */ }

	/* ... */

	MLClose(link);
	MLDeinitialize(env);
	return 0;
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[MLGetYieldFunction(), paclet:ref/c/MLGetYieldFunction])}})}})