Message Boards Message Boards

2
|
4822 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

LibraryLink: How to use a WSTP connection when an abort is in progress?

Posted 9 years ago
POSTED BY: Szabolcs Horvát
2 Replies
POSTED BY: Szabolcs Horvát

First, you should make sure you're using 10.2. There was a serious bug in earlier versions that didn't handle LinkObjects correctly in an abort scenario.

Second, what you're trying to do really is, if possible, completely inadvisable. When you call back into the kernel, you're calling directly back into code which aggressively is checking for aborts, and really, really wants to fail and throw $Aborted if that happens. You could wrap your invocations of the LibraryFunction objects in AbortProtect. In that way, you can guarantee that if an abort happens, either your function will never be called, or that the abort will not be handled inside your function (including in the callback processing).

And, yes, one of the things that will happen in an abort is to throw away your link. Why? Because an abort may have happened in the middle of link writing/reading operations. Which means that the link is now in an uncertain and unrecoverable state. This scenario is carefully avoided in the Mathematica code proper, but as far as the kernel is concerned, a DLL has been handling that link doing heaven knows what with it, so its state really is unknowable.

POSTED BY: John Fultz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract