[Haskell-cafe] FFI woes!

Jules Bean jules at jellybean.co.uk
Thu Dec 16 10:32:10 EST 2004


On 16 Dec 2004, at 15:20, Sebastian Sylvan wrote:

> I really don't want to poll the sound sample all the time since it
> uses up resources needlessly. If it comes to that, though, it's pretty
> much guaranteed that it will get the job done.
>

A thread which polls once per second (and sleeps otherwise) is a 
negligible overhead. I wouldn't lose sleep over that.

> This is what I tried to do. I've now tried to do it with weak pointers
> as well. I get the finalizer to run, but for some reason the finalizer
> for the sound resource gets invoked before the finalizer for the
> channel. This is extremply strange since the channel contains a
> reference to the "ForeignPtr CSoundSample" so I wouldn't expect the
> sound resource finalizer to EVER get invoked while there are still
> channels around that are referencing it.
>

Well suppose the channel goes out of scope. Now the channel and the 
sound are both out of scope, so they can be GC'ed. There is no 
guarantee in which order the finalizers will be invoked, so it's 
perfectly possible that the sound finalizer runs before the channel 
finalizer.

Jules



More information about the Haskell-Cafe mailing list