caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: david.baelde@ens-lyon.org
Cc: Goswin von Brederlow <goswin-v-b@web.de>,
	Savonet's developpers list <savonet-devl@lists.sourceforge.net>,
	Caml Mailing List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Re: Random segfaults / out of memory
Date: Tue, 30 Mar 2010 17:57:10 +0200	[thread overview]
Message-ID: <4BB21F56.9070802@inria.fr> (raw)
In-Reply-To: <53c655921003300014s2c7b05eax24b91edbb0d0d9ec@mail.gmail.com>

> So, is it really forbidden to release the global lock in a noalloc function?

Yes.  Actually, it is forbidden to call any function of the OCaml
runtime system from a noalloc function.

Explanation: ocamlopt-generated code caches in registers some global
variables of importance to the OCaml runtime system, such as the
current allocation pointer.

When calling a regular (no-"noalloc") C function from OCaml, these
global variables are updated with the cached values so that everything
goes well if the C function allocates, triggers a GC, or releases the
global lock (enabling a context switch).

This updating is skipped when the C function has been declared
"noalloc" -- this is why calls to "noalloc" functions are slightly
faster.  The downside is that the runtime system is not in a
functioning state while within a "noalloc" C function, and must
therefore not be invoked.

The cost of updating global variables is small, so "noalloc" makes
sense only for short-running C functions (say, < 100 instructions) like
those from the math library (sin, cos, etc).  If the C function makes
significant work (1000 instructions or more), just play it safe and
don't declare it "noalloc".

Hope this helps,

- Xavier Leroy


  reply	other threads:[~2010-03-30 15:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-17  8:27 Rewriting the Digest module causes linking errors Goswin von Brederlow
2010-03-17  8:39 ` [Caml-list] " Mark Shinwell
2010-03-17  9:53   ` Goswin von Brederlow
2010-03-17 16:39     ` Random segfaults / out of memory [Was: Re: [Caml-list] Rewriting the Digest module causes linking errors] Goswin von Brederlow
2010-03-18 10:56       ` Random segfaults / out of memory Goswin von Brederlow
2010-03-30  7:14         ` [Caml-list] " David Baelde
2010-03-30 15:57           ` Xavier Leroy [this message]
2010-03-30 16:19             ` Markus Mottl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BB21F56.9070802@inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=david.baelde@ens-lyon.org \
    --cc=goswin-v-b@web.de \
    --cc=savonet-devl@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).