Fri, 9 Jun 2000 08:14:13 -0700, Simon Marlow <[EMAIL PROTECTED]> pisze:

> And which thread should get the exception?

IMHO the main thread is not a bad choice: simple and deterministic,
a programmer knows where to install the handler (as opposed to "one
that was allocating at the time" and "one that has allocated most"),
consistently terminates the program when no handler was installed
explicitly.

This is a bit different than killing processes in OS, because
* there is a handler that the programmer wants to be called,
* threads cooperate, processes are usually independent and created
  by different users.



For an example of usage, i.e. when out of heap is not fatal, let's
consider a program that maintains a cache of something, and wants
to purge some cache when went out of heap. Seems to work: the main
thread would install a handler around a takeMVar, the handler would
free some cache and loop again.

Another example. Say it's GIMP. I start a computation that I know that
uses a lot of memory, and want to get "sorry, couldn't complete, out
of memory" when needed. This computation might be in any thread. Hmm,
not so nice, because handling cannot be local. Anyway, the computation
could be moved to a separate thread, the main thread would maintain
ThreadIds of such threads, and kill any of them according to some
chosen policy when run out of heap, informing its parent about
the crime instead of the killed thread that would inform about
completion. Modulo fixing some races.

I am looking for examples to see how they could be handled in different
variants. The second example is easier in "one that was allocating
at the time" (assuming that no other threads are working), but the
first is quite impossible then. I might not want to kill anything yet,
freeing some memory by other means. Any more examples?

Borland Pascal has an out of memory handler that AFAIR returns a code
what to do: retry the allocation, abort the program or return a null
pointer.

I don't know how to ensure that the handler will not use too much
memory before it manages to free some.



PS. The default heap limit is 64MB. Shouldn't it depend on physical
memory or user's limits or free memory or such? Or simpler: check an
enviromnent variable for default RTS options.

-- 
 __("<    Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
 \__/              GCS/M d- s+:-- a23 C+++$ UL++>++++$ P+++ L++>++++$ E-
  ^^                  W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK                  5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-


Reply via email to