Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000497OCamlOCaml generalpublic2001-08-28 04:212001-08-28 15:00
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000497: Does Gc.create_alarm work?
DescriptionFull_Name: David Fox
Version: 3.02
OS: Linux
Submission from: adsl-63-196-84-93.dsl.sndg02.pacbell.net (63.196.84.93)


It seems to me that the following should generate output:

  let alarm = Gc.create_alarm (fun () -> print_endline "Hello"; flush stdout)
  let _ = Gc.major ()

But I get nothing running 3.02 on a Linux machine.

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0000658)
administrator (administrator)
2001-08-28 15:00

> Full_Name: David Fox
> Version: 3.02
>
> let alarm = Gc.create_alarm (fun () -> print_endline "Hello"; flush stdout)
> let _ = Gc.major ()
>
> But I get nothing running 3.02 on a Linux machine.

You're right, I made a stupid bug in the implementation of GC alarms.
This is now fixed in the working version and a patch is included in this mail.

You'll have to call Gc.major twice before you start seeing the messages,
though. That's because alarms are based on finalised values, and the
alarm record is not unreachable on the first GC after its allocation.

Thanks for the report,

-- Damien

Index: stdlib/gc.ml
===================================================================
RCS file: /net/pauillac/caml/repository/csl/stdlib/gc.ml,v
retrieving revision 1.12
diff -c -r1.12 gc.ml
*** gc.ml 2001/02/05 14:59:23 1.12
--- gc.ml 2001/08/28 12:47:44
***************
*** 75,93 ****
  external finalise : ('a -> unit) -> 'a -> unit = "final_register";;
  
  
! type alarm = {mutable active : bool; f : unit -> unit};;
  
! let rec call_alarm a =
! if a.active then begin
! finalise call_alarm a;
! a.f ();
    end;
  ;;
  
  let create_alarm f =
! let a = { active = true; f = f } in
! finalise call_alarm a;
    a
  ;;
  
! let delete_alarm a = a.active <- false;;
--- 75,96 ----
  external finalise : ('a -> unit) -> 'a -> unit = "final_register";;
  
  
! type alarm_rec = {active : alarm; f : unit -> unit}
! and alarm = bool ref
! ;;
  
! let rec call_alarm arec =
! if !(arec.active) then begin
! finalise call_alarm arec;
! arec.f ();
    end;
  ;;
  
  let create_alarm f =
! let a = ref true in
! let arec = { active = ref true; f = f } in
! finalise call_alarm arec;
    a
  ;;
  
! let delete_alarm a = a := false;;

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker