On Tue, 13 Oct 2009, Felipe Sateler wrote:

I've always assumed that malloc (and thus realloc) can sleep.

I believe the creators of the Single UNIX Specification didn't share (or at least, didn't codify) this assumption. As a general rule, any system interface that is designed to wait (= hang indefinitely) on a resource

- can be either used in some non-blocking way when it returns EAGAIN,
- or it can be interrupted by a signal, when it returns -1 and sets errno
  to EINTR,
- or you can specify a time limit,
- or it is a thread cancellation point.

In short, if a system interface goes to sleep by design, it can be woken up in a way or another, or else the system interface description explicitly says it cannot be woken up. The malloc() description under [0] makes me think that malloc() cannot hang indefinitely by design.

[0] http://www.opengroup.org/onlinepubs/9699919799/functions/malloc.html

Cheers,
lacos


--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to