Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From the documentation of <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-ForeignPtr.html#v:newForeignPtr" rel="nofollow noreferrer">Foreign.Foreign.newForeignPtr</a>:</p> <blockquote> <p>Note that there is no guarantee on how soon the finaliser is executed after the last reference was dropped; this depends on the details of the Haskell storage manager. Indeed, there is no guarantee that the finalizer is executed at all; a program may exit with finalizers outstanding.</p> </blockquote> <p>So you're running into undefined behaviour: i.e., anything can happen, and it may change from platform to platform (as we saw under Windows) or release to release.</p> <p>The cause of the difference in behaviour you're seeing between the two functions may be hinted at by the documentation for <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-Concurrent.html#v:newForeignPtr" rel="nofollow noreferrer">Foreign.Concurrent.newForeignPtr</a>:</p> <blockquote> <p>These finalizers necessarily run in a separate thread...</p> </blockquote> <p>If the finalizers for the Foreign.Foreign version of the function use the main thread, but the Foreign.Concurrent ones use a separate thread, it could well be that the main thread shuts down without waiting for other threads to complete their work, so the other threads never get to run the finalization.</p> <p>Of course, the docs for the Foreign.Concurrent version do claim,</p> <blockquote> <p>The only guarantee is that the finalizer runs before the program terminates.</p> </blockquote> <p>I'm not sure that they actually ought to be claiming this, since if the finalizers are running in other threads, they can take an arbitrary amount of time to do their work (even block forever), and thus the main thread would never be able to force the program to exit. That would conflict with this from <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent.html" rel="nofollow noreferrer">Control.Concurrent</a>:</p> <blockquote> <p>In a standalone GHC program, only the main thread is required to terminate in order for the process to terminate. Thus all other forked threads will simply terminate at the same time as the main thread (the terminology for this kind of behaviour is "daemonic threads"). </p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload