[Haskell-cafe] Locking of threads in one OS thread

Nikolay Amiantov nikoamia at gmail.com
Tue Aug 26 14:22:58 UTC 2014

On Wed, Aug 20, 2014 at 4:36 PM, Alexander Kjeldaas <
alexander.kjeldaas at gmail.com> wrote:

> Reading errno directly after the FFI call can eliminate heap overflows,
> but the async exception and timer issues still seem possible.

I have played around a bit and I can't understand what's going on with this
anymore. Check out this example:
https://gist.github.com/abbradar/76dafcee1807c9c5ac4d. Compile it with "ghc
test_c.c test.hs". I used "mask_" here to check if it can fix the problem.

There will be multiple discrepancies seen between written and read values
because of threads preemption if my_errno is used. However, if you use
"errno" (change #define for that) instead, everything seems good.

Anyway, it looks like getErrno and friends rely on this magical behaviour
of errno -- if some other library which uses global error state like
"my_errno" in example is used (I remember SDL doing that, and I have also
done it myself), there should be problems without some way to temporary
disable threads preemption, which I haven't found. Hence -- should I maybe
post a bug report about this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140826/f2d3b78e/attachment.html>

More information about the Haskell-Cafe mailing list