# Nondeterministic errors in compiled code under macOS

**URL:** <https://swi-prolog.discourse.group/t/nondeterministic-errors-in-compiled-code-under-macos/2439>\
**Category:** Help!\
**Tags:** bug\
**Created:** [May 31, 2020, 8:48am UTC](https://swi-prolog.discourse.group/t/nondeterministic-errors-in-compiled-code-under-macos/2439 "2020-05-31T08:48:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iam](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@Iam](https://swi-prolog.discourse.group/u/Iam)\
**Post date:** [May 31, 2020, 8:48am UTC](https://swi-prolog.discourse.group/t/nondeterministic-errors-in-compiled-code-under-macos/2439/1 "2020-05-31T08:48:31Z")

</div>

I’m using: SWI-Prolog version 8.1.26  
I am compiling the code with \> swipl --goal=main -o tester4 -c tester.pl

I want the code to:  
Behave the same if executed multiple times with exactly the same input data

But what I’m getting is:  
The compiled program sometimes hangs and sometimes (with exactly the same input) does not hang. (I assume it is a memory leak in the generate C-Code.)  
This error occurred multiple times when using SWI-Prolog version 8.1.26 under macOS version Mojave 10.14.6. But I could not reproduce the error, when using SWI-Prolog version 8.1.26 under Parallels desktop Windows on the same Mac computer, i.e., compiled under Parallels Windows the code produces always the same correct results.

My code looks like this:

As my code contains the solutions to the assignments for my students, pIease ask for the code via email to [stb@upb.de](mailto:stb@upb.de).

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 31, 2020, 9:06am UTC](https://swi-prolog.discourse.group/t/nondeterministic-errors-in-compiled-code-under-macos/2439/2 "2020-05-31T09:06:00Z")

</div>

You can send the code in a private message. If it can be reproduced and is still relevant (the last fixup tp 8.3 fixed quite a few issues), it is worth a try. Make sure it is complete though, so I can really run it.

---

<div class="post-metadata">

**Author:** ![Iam](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@Iam](https://swi-prolog.discourse.group/u/Iam)\
**Post date:** [May 31, 2020, 10:02am UTC](https://swi-prolog.discourse.group/t/nondeterministic-errors-in-compiled-code-under-macos/2439/3 "2020-05-31T10:02:11Z")

</div>

Hello Jan,

thank you for your fast response!

Meanwhile, I have also tested the code under opensuse, and I got the same nondeterministic hanging errors as under macOS  
(which I could not yet reproduce under Parallels Windows).

Please find attached the .zip-file including the code and 2 screenshots.

Regards,

Stefan Böttcher

(Attachment Code sometimes hanging under macOS.zip is missing)

---

<div class="post-metadata">

**Author:** ![Iam](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@Iam](https://swi-prolog.discourse.group/u/Iam)\
**Post date:** [May 31, 2020, 10:48am UTC](https://swi-prolog.discourse.group/t/nondeterministic-errors-in-compiled-code-under-macos/2439/6 "2020-05-31T10:48:49Z")

</div>

In this thread, I can see everything (including the code that should be kept private).  
Is this a private channel?

Stefan

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 31, 2020, 2:53pm UTC](https://swi-prolog.discourse.group/t/nondeterministic-errors-in-compiled-code-under-macos/2439/8 "2020-05-31T14:53:20Z")

</div>

> [@Iam](#):
>
> Meanwhile, I have also tested the code under opensuse, and I got the same nondeterministic hanging errors as under macOS

Same under Ubuntu 20.04. Turns out to be a problem with library(time) in terminating the scheduler thread that is used to signal timeouts. I think the same issue may actually cause alarms and call\_with\_time\_limit/2 not to trigger, although I have seen no evidence that this happens.

Pushed a fix (for the `clib` submodule). Hope you can deal with just an update to the source?

---

<div class="post-metadata">

**Author:** ![Iam](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@Iam](https://swi-prolog.discourse.group/u/Iam)\
**Post date:** [June 12, 2020, 9:51am UTC](https://swi-prolog.discourse.group/t/nondeterministic-errors-in-compiled-code-under-macos/2439/9 "2020-06-12T09:51:15Z")

</div>

Thank you very much for caring about the code and fixing the bugs!
