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

Different behavior of program compiled with ocamlc vs ocamlopt #7032

Closed
vicuna opened this issue Oct 27, 2015 · 3 comments
Closed

Different behavior of program compiled with ocamlc vs ocamlopt #7032

vicuna opened this issue Oct 27, 2015 · 3 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Oct 27, 2015

Original bug ID: 7032
Reporter: jura
Status: closed (set by @alainfrisch on 2015-11-12T14:42:46Z)
Resolution: not a bug
Priority: normal
Severity: minor
Platform: x86_64GNU/Linux3.13.0-66-generic
OS: Ubuntu
OS Version: 14.04.3
Version: 4.02.3
Category: ~DO NOT USE (was: OCaml general)
Tags: suggest_closing

Bug description

The program is:

exception Timeout
 
let sigalrm_handler = Sys.Signal_handle (fun _ -> raise Timeout)
 
let timeout f arg time default_value =
  let old_behavior = Sys.signal Sys.sigalrm sigalrm_handler in
  let reset_sigalrm () = Sys.set_signal Sys.sigalrm old_behavior  in
  ignore (Unix.alarm time);
  try
    let res = f arg in
    reset_sigalrm ();
    res  
  with exc ->
    reset_sigalrm ();
    if exc=Timeout then default_value
    else raise exc
 
let rec loop x = loop x
 
 
let _ =  
  Printf.printf "Got %s\n%!" (timeout loop 0 2 "timeout");

When compiling with "ocamlc unix.cma timeout.ml" the program terminates, but when compiling with "ocamlopt unix.cmxa timeout.ml" the program does not terminate.

Steps to reproduce

Compile the program given in the description with ""ocamlc unix.cma timeout.ml" then run with "./a.out". Then "rm a.out && ocamlopt unix.cmxa timeout.ml && ./a.out" and observe the program not terminate.

Additional information

Also reproduce on Mac osx 10.10

File attachments

@vicuna
Copy link
Author

vicuna commented Oct 27, 2015

Comment author: @dbuenzli

The non-termination is somehow expected see:

https://ocaml.github.io/ocamlunix/signals.html#sec86

Maybe the discrepancy isn't but I'm not sure I would bother.

@vicuna
Copy link
Author

vicuna commented Oct 27, 2015

Comment author: @dbuenzli

Oh in fact it is documented here:

http://caml.inria.fr/pub/docs/manual-ocaml/native.html#sec274

@vicuna
Copy link
Author

vicuna commented Nov 2, 2015

Comment author: jura

Thank you very much dbuenzli

@vicuna vicuna closed this as completed Nov 12, 2015
@vicuna vicuna added the bug label Mar 20, 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