caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Type Safety and Interruptions
@ 2003-08-13  4:10 Oleg Trott
  2003-08-18 12:40 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Oleg Trott @ 2003-08-13  4:10 UTC (permalink / raw)
  To: caml-list

Hi

Are there any guarantees about type safety even when program execution is 
interrupted?

As a simple example, suppose f is a function that modifies its argument 
(array) frequently, x is some value, and I type in the toplevel:


# (* ..... *)
#  let a = Array.make 100000 x;;
#  f a;;
Interrupted.


and interrupt it before f finishes. Is it at all possible for array "a" to 
be in some odd state when its `value' is inconsistent with its type?

What if "f" also contains calls to foreign (C/FORTRAN) functions?

Thanks in advance

-- 
Oleg Trott <oleg_trott@columbia.edu>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Type Safety and Interruptions
  2003-08-13  4:10 [Caml-list] Type Safety and Interruptions Oleg Trott
@ 2003-08-18 12:40 ` Xavier Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 2003-08-18 12:40 UTC (permalink / raw)
  To: Oleg Trott; +Cc: caml-list

> Are there any guarantees about type safety even when program execution is 
> interrupted?

Yes.  Signals are not processed in a completely asynchronous manner.
Rather, they are recorded and processed later when the program reaches
a safe program point, e.g. not in the middle of an allocation, an
initialization, nor a GC.

> As a simple example, suppose f is a function that modifies its argument 
> (array) frequently, x is some value, and I type in the toplevel:
> 
> 
> # (* ..... *)
> #  let a = Array.make 100000 x;;
> #  f a;;
> Interrupted.
> 
> and interrupt it before f finishes. Is it at all possible for array "a" to 
> be in some odd state when its `value' is inconsistent with its type?

No, this cannot happen.  The array may be partially modified
(depending on what f did before being interrupted), but it will always
hold valid integers.

> What if "f" also contains calls to foreign (C/FORTRAN) functions?

Same thing.  By default, the signals are delayed till the foreign
function returns and the Caml program hits a safe point.  Some foreign
functions can explicitly declare a "blocking section" where they are
going to block for an unbounded amount of time, and within this
section signals will be processed immediately.  However, it is part of
the "blocking section" contract that the C function must not touch the
Caml heap as long as it is within the blocking section, so again heap
corruption cannot occur.

Hope this helps,

- Xavier Leroy

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-08-18 12:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-13  4:10 [Caml-list] Type Safety and Interruptions Oleg Trott
2003-08-18 12:40 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).