MLEnableLinkLock (C Function)

MLEnableLinkLock has been replaced by WSEnableLinkLock.

void MLEnableLinkLock ( MLINK l )

turns on thread safety for the MathLink connection specified by l.

Details

  • By default, MathLink link objects are not thread safe with respect to calling MathLink API functions for the same link from multiple threads simultaneously. After calling MLEnableLinkLock() for a link object, that link can then be used simultaneously from multiple threads of execution.
  • Thread safety introduces a small performance penalty in order to maintain the integrity of the internal data stream for a given link object. All threaded programs that use shared resources incur this penalty when protecting access to a shared resource.
  • Thread safety can be disabled for l by calling MLDisableLinkLock().
  • MLEnableLinkLock() is declared in the MathLink header file mathlink.h.

Examples

Basic Examples  (1)

#include "mathlink.h"

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

    env = MLInitialize((MLEnvironmentParameter)0);
    if(env == (MLENV)0)
    { /* Unable to create MathLink environment object */ }

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

    MLActivate(link);

    MLEnableLinkLock(link);

    /* ... */

    MLClose(link);
    MLDeinitialize(env);

    return 0;
}