chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] remove enable/disable interrupt flag


From: Alaric Snell-Pym
Subject: Re: [Chicken-users] remove enable/disable interrupt flag
Date: Thu, 29 Sep 2011 16:02:10 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/29/2011 02:43 PM, Jörg F. Wittenberger wrote:

> (define (chicken-enable-interrupts!) (set! C_interrupts_enabled #t))
> (define chicken-disable-interrupts! (foreign-lambda void
> "C_disable_interrupts"))
>
> (let ((pid (begin
>  (chicken-disable-interrupts!)
>  ((foreign-lambda int "fork")) ))
> (if (not (= pid 0)) (chicken-enable-interrupts!))
> ...
> )

To be honest, doing *anything* between fork and exec is pretty
questionable. There's the big issue that threads might not be expecting
to be randomly duplicated by actions in some other thread, and proceed
to do something twice because of it (not a great issue if it's just
touching RAM, but a great issue if it involves I/O or mutual exclusion
mechanisms). Then there's the fact that you can't use vfork if you do
anything other than go straight into an exec, so you need to pay the
cost of duplicating the entire address space with CoW mappings (which
turned out to be a critical performance factor in a fork-heavy workload
here at work, recently!).

Having said that, there are good uses of fork() other than as a "vfork()
then exec()" pair; you just need to be VERY CAREFUL, and get
whole-program cooperation. Eg, don't initialise some third-party library
in the parent, then use it in the child; only take your own state across
the fork, and audit it for the consequences.

(Good uses of fork() I have seen include redis' technique of forking to
get an atomic copy of the process memory to snapshot to disk while the
parent continues to process updates, and software forking off its own
daemon processes as a form of threading or to ensure isolation from the
parent for security reasons! But all of these cases involve careful
consideration of the transmission of state from parent to child.)

POSIX says that fork needs to produce only a single surviving POSIX
thread in the child. Perhaps Chicken fork needs to do the same with
Chicken threads.

Chicken fork - no food jokes!

ABS

- --
Alaric Snell-Pym
http://www.snell-pym.org.uk/alaric/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6EiHIACgkQRgz/WHNxCGr0zwCfUWMseuGomWLBL/jgQGHUtEPE
RXkAn1C0eXxK1zfXgwfoCR4OFKstU7X2
=d9Ca
-----END PGP SIGNATURE-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]