ForeignPtr and -threaded
PHO
phonohawk at ps.sakura.ne.jp
Sun Jul 22 22:07:40 EDT 2007
From: Bulat Ziganshin <bulat.ziganshin at gmail.com>
Subject: Re: ForeignPtr and -threaded
Date: Sun, 22 Jul 2007 17:48:05 +0400
> try to add performGC at end - this should force collecting garbage and
> therefore printing of string. otherwise, it's ok - there is no guarantee
> that GC will be performed and therefore that you finalizer will be
> performed. it's rather stanard behavior for GC languages - finalizers
> are almosr useless there
So I changed the code like this but the result was exactly the
same. The documentations of both Foreign.ForeignPtr (*1) and
Foreign.Concurrent (*2) say "The only guarantee is that the finalizer
runs before the program terminates." So I expected the finalizer to be
called.
import Foreign.Marshal.Alloc
import Foreign.Ptr
import Foreign.ForeignPtr
import System.Mem
import qualified Foreign.Concurrent as Conc
main = work >> performGC
where
work = do mem <- mallocBytes 10
Conc.newForeignPtr mem $ print "called"
*1: http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-ForeignPtr.html
*2: http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-Concurrent.html
_______________________________________________________
- PHO - http://ccm.sherry.jp/
OpenPGP public key: 1024D/1A86EF72
Fpr: 5F3E 5B5F 535C CE27 8254 4D1A 14E7 9CA7 1A86 EF72
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20070723/cd60720f/attachment.bin
More information about the Glasgow-haskell-users
mailing list