Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does Gc.create_alarm work? #2933

Closed
vicuna opened this issue Aug 28, 2001 · 1 comment
Closed

Does Gc.create_alarm work? #2933

vicuna opened this issue Aug 28, 2001 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Aug 28, 2001

Original bug ID: 497
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_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.

@vicuna
Copy link
Author

vicuna commented Aug 28, 2001

Comment author: administrator

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;;

@vicuna vicuna closed this as completed Aug 28, 2001
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant