ocaml/ocamlunix

Possible mistake in section 4.6 The passage of time

Opened this issue · 0 comments

cwfoo commented

In the example in section 4.6 The passage of time:

1 let sleep s =
2   let old_alarm = signal sigalrm (Signal_handle (fun s -> ())) in 
3   let old_mask = sigprocmask SIG_UNBLOCK [ sigalrm ] in
4   let _ = alarm s in
5   let new_mask = List.filter (fun x -> x <> sigalrm) old_mask in
6   sigsuspend new_mask;
7   let _ = alarm 0 in
8   ignore (signal sigalrm old_alarm);
9   ignore (sigprocmask SIG_SETMASK old_mask);;

The explanation says: "Note that line 9 could be placed immediately after line 2 because the call to sigsuspend preserves the signal mask".

Isn't it invalid to place line 9 immediately after line 2? Line 9 uses old_mask, but old_mask is not yet defined if line 9 is placed right after line 2. Is there a mistake in the explanation?