To clarify some of the points in this discussion:
Alastair is right in that the finalizer thread isn't necessarily run to
completion if the main thread exits. GHC does run any outstanding
finalizers at the end of the program, but it doesn't necessarily
complete any existing finalizer threads
Arjan van IJzendoorn wrote:
I couldn't get finalisers to work either with the newForeignPtr from
this module. I didn't know how to create a proper FunPtr. In
Foreign.Concurrent there is a newForeignPtr that is easier to use:
[deleted]
I seem to remeber running in to this problem a
Krasimir Angelov wrote:
The problem here is that the external functions
(instances of type FunPtr) are always executed with
ccall convention regardless of stdcall declaration in
the foreign import. The workaround is to write simple
stub function in C with ccall convention.
You are right, I did
Niklas Sorensson wrote:
Arjan van IJzendoorn wrote:
I couldn't get finalisers to work either with the newForeignPtr from
this module. I didn't know how to create a proper FunPtr. In
Foreign.Concurrent there is a newForeignPtr that is easier to use:
[deleted]
I seem to remeber running in to
Arjan van IJzendoorn wrote:
foreign import ccall ... finaliserCreator :: IO (FunPtr (Ptr a -
IO ()))
and then
finaliser - finaliserCreator
AFAIK this creates some dynamic machine code in malloce'd area, so there
is need to free it afterward with freeHaskellFunPtr. Are you doing that?
AFAIK this creates some dynamic machine code in malloce'd area, so there
is need to free it afterward with freeHaskellFunPtr. Are you doing that?
How? And when? I did not find any suitable place in my code to call
freeHaskellFunPtr.
Machine code is dynamically created when you turn a Haskell
Arjan van IJzendoorn wrote:
I couldn't get finalisers to work either with the newForeignPtr from
this module. I didn't know how to create a proper FunPtr. In
Foreign.Concurrent there is a newForeignPtr that is easier to use:
[deleted]
So here is the new code:
{-# OPTIONS -fglasgow-exts #-}
[program deleted]
So, this basically means that my finalizer did not get run :(
[...]
It should run, in separate thread or not, it doesn't matter here.
Any ideas why doesn't it work?
Hopefully the GHC folk will correct me if I'm wrong but I think what happens
is:
- you allocate object
Alastair Reid wrote:
You could give the finalizer thread a chance to run by calling
Control.Concurrent.yield before exiting:
Thanks, it worked. This is ok for me, because my finalizer only closes
some handles. Those are closed at program end anyway, so in this case I
can live with it.
BUT:
I don't see why GHC can't have a 'callAllOutstandingFinalizers' call
as part of _exit() or something...
Keean.
___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Alastair Reid wrote:
import Foreign.ForeignPtr
I couldn't get finalisers to work either with the newForeignPtr from
this module. I didn't know how to create a proper FunPtr.
You create a FunPtr using foreign import:
foreign import ccall malloc.h free free_ptr :: FunPtr (Ptr a - IO ())
foreign
BUT: This can make some people unhappy. Isn't there a more deterministic
way to schedule finalizers?
I wrote the Hugs version which does try to be more deterministic so I'm
probably not the best qualified to write about what's wrong with GHC :-)
But, I think part of the problem is that GHC
On Thursday 10 June 2004 12:07, MR K P SCHUPKE wrote:
I don't see why GHC can't have a 'callAllOutstandingFinalizers' call
as part of _exit() or something...
You can do that if your finalizers are written in C (and don't call back into
Haskell) but if they are written in Haskell then you
Hi all,
I would like to attach finalizer (written in Haskell) to some pointer.
When the pointer won't be needed any more, finalizer should run. So here
is the code:
module Main where
import Foreign.Ptr
import Foreign.ForeignPtr
import Foreign.Marshal.Alloc
foreign import stdcall wrapper mkFin
HI Gracjan,
I would like to attach finalizer (written in Haskell) to some pointer.
When the pointer won't be needed any more, finalizer should run. So
here is the code:
import Foreign.ForeignPtr
I couldn't get finalisers to work either with the newForeignPtr from
this module. I didn't know how
import Foreign.ForeignPtr
I couldn't get finalisers to work either with the newForeignPtr from
this module. I didn't know how to create a proper FunPtr.
You create a FunPtr using foreign import:
foreign import ccall malloc.h free free_ptr :: FunPtr (Ptr a - IO ())
In Foreign.Concurrent
16 matches
Mail list logo