13

Cross-posted to Wolfram Community


The following is from the comparison between WSTP (MathLink) and LibraryLink in the documentation:

When the Wolfram Language is waiting for a WSTP application to return a result, it can be used to service preemptive computations such as those needed for user interface operations. When a library function is running this will not happen without effort by the author of the library.

(Emphasis by me.)

What do I need to do to allow for preemptive computations to be serviced while running LibraryLink functions?

Is there a function similar to libData->AbortQ() that I need to call from time to time? AbortQ() itself won't allow for this (I already checked). I did not find anything promising in WolframLibrary.h, but the documentation suggests that there should be a way.


Update

The following works, but I am not sure of its performance impact and I worry that this is just an abuse of functionality meant for something else.

Periodically execute the following in the LibraryLink function (the same way you would call AbortQ())

MLINK lp = libData->getMathLink(libData);
libData->processMathLink(lp);

Is this the right way to do it?

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263

1 Answers1

3

John Fultz has responded on Wolfram Community. It is sufficient to keep calling libData->AbortQ(). Embarrassingly I must have made a mistake when testing this, as it does work. I should note though that AbortQ() must be called frequently for it to be fluid, I originally only called it every second.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263