RE: finalisers not being run

1999-12-10 Thread Simon Marlow

Meurig Sages writes:

> I've got the following program. It depends heavily on 
> finalisers being run
> regularly as it goes along. I therefore call yield regularly to try to
> ensure this.
> This works perfectly under the original ghc-4.04 release, 
> weak pointers are
> garbage collected and finalisers run regularly.
> 
> However, with the cvs release of ghc this does not happen. 
> When I run the
> program normally finalisers are only run at the end of the 
> program. This is
> despite the fact that their associated weak pointers have been garbage
> collected much earlier, and yield is being called regularly. 
> If I run with
> +RTS -G1, which makes life even better in 4.04 (as weak 
> pointers are garbage
> collected more regularly), with 4.05 life gets even worse. 
> The finalisers
> are NEVER run. This happens whether I compile with or without -O.
> 
> Perplexed,

Well spotted.  I broke this with the recent scheduler upheaval.  I've
checked in the fix, and the following patch should get you going:

*** Weak.c  1999/07/06 15:05:49 1.11
--- Weak.c  1999/12/10 15:50:10 1.12
***
*** 1,5 
  /*

-
!  * $Id: Weak.c,v 1.11 1999/07/06 15:05:49 sof Exp $
   *
   * (c) The GHC Team, 1998-1999
   *
--- 1,5 
  /*

-
!  * $Id: Weak.c,v 1.12 1999/12/10 15:50:10 simonmar Exp $
   *
   * (c) The GHC Team, 1998-1999
   *
***
*** 58,72 
  scheduleFinalizers(StgWeak *list)
  {
StgWeak *w;

for (w = list; w; w = w->link) {
  IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n",
w, w->key));
  if (w->finalizer != &NO_FINALIZER_closure) {
  #ifdef INTERPRETER
!   createGenThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
  #else
!   createIOThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
  #endif
  }
  w->header.info = &DEAD_WEAK_info;
}
--- 58,74 
  scheduleFinalizers(StgWeak *list)
  {
StgWeak *w;
+   StgTSO *t;

for (w = list; w; w = w->link) {
  IF_DEBUG(weak,fprintf(stderr,"Finalising weak pointer at %p -> %p\n",
w, w->key));
  if (w->finalizer != &NO_FINALIZER_closure) {
  #ifdef INTERPRETER
!   t = createGenThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
  #else
!   t = createIOThread(RtsFlags.GcFlags.initialStkSize, w->finalizer);
  #endif
+   scheduleThread(t);
  }
  w->header.info = &DEAD_WEAK_info;
}



finalisers not being run

1999-12-10 Thread Meurig Sage

Hi,
I've got the following program. It depends heavily on finalisers being run
regularly as it goes along. I therefore call yield regularly to try to
ensure this.
This works perfectly under the original ghc-4.04 release, weak pointers are
garbage collected and finalisers run regularly.

However, with the cvs release of ghc this does not happen. When I run the
program normally finalisers are only run at the end of the program. This is
despite the fact that their associated weak pointers have been garbage
collected much earlier, and yield is being called regularly. If I run with
+RTS -G1, which makes life even better in 4.04 (as weak pointers are garbage
collected more regularly), with 4.05 life gets even worse. The finalisers
are NEVER run. This happens whether I compile with or without -O.

Perplexed,
 Meurig

PS I enclose the program.
I run it with
main 1000 10

The first argument says how many times to loop round.
The second says how regularly to call yield.

The program prints killed when a weak pointer dies, and finalised when a
weak pointer is finalised.



 sendsimon.tar.gz