WSEnableLinkLock()
This feature is not supported on the Wolfram Cloud.

void WSEnableLinkLock (WSLINK l)
turns on thread safety for the WSTP connection specified by l.

DetailsDetails

  • By default, WSTP link objects are not thread safe with respect to calling WSTP API functions for the same link from multiple threads simultaneously. After calling WSEnableLinkLock() 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 WSDisableLinkLock().
  • WSEnableLinkLock() is declared in the WSTP header file wstp.h.

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

#include "wstp.h"

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

    env = WSInitialize((WSEnvironmentParameter)0);
    if(env == (MLENV)0)
    { /* Unable to create WSTP environment object */ }

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

    WSActivate(link);

    WSEnableLinkLock(link);

    /* ... */

    WSClose(link);
    WSDeinitialize(env);

    return 0;
}