caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Erik de Castro Lopo <mle+ocaml@mega-nerd.com>
To: Caml-list@yquem.inria.fr
Subject: Threads, Signals and Events
Date: Fri, 15 Feb 2008 09:19:10 +1100	[thread overview]
Message-ID: <20080215091910.bb982431.mle+ocaml@mega-nerd.com> (raw)

Hi all,

I'm doing some systems programming where I need to use threads
(standard threads, not cothreads), signals and events. The program
has a couple of things to do:

 a) Start program X, do a wait on its pid and restart X if it dies
    and log information to syslog.
 b) Periodically run other system checks and log results to syslog.
    Certain types of system failures need to be communicated to
    program X so that it can modify its behaviour.
 c) Catch SIGHUP, and on reception, kill program X (send SIGHUP first
    and if that doesn't work SIGTERM and finally SIGKILL) and then
    exit itself.

Since the system checks can take some time (mostly waiting for the
kernel to do stuff rather than intensive processing) and program X
needs to be restarted immediately if it dies, using threads seems 
to be an obvious solution.

However, reading between the lines of thread.mli suggests that
signals should be blocked on all threads but one which catches
signals using Thread.wait_signal and then sends events using the
Event module to the other threads.

This makes for four threads:

 - Main thread which waits for SIGHUP and sends an Event when it
   does.
 - Monitor thread which waits for program X to exit using
   Thread.wait_pid.
 - A syscheck thread which pretty much does its thing and log its
   results by sending an Event to the logger thread.
 - Logger thread which receives events from the other threads and
   writes to syslog.

The problem with the above is that the monitor thread needs to wait
on both a pid and an Event and I can't see any way to do that.

Anybody have any suggestions? This is on Linux btw.

Cheers,
Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"An older MS internal whitepaper from August 2000 on switching
Hotmail, which MS acquired in 1997, from front-end servers
running FreeBSD and back-end database servers running Solaris
to a whole farm running Win2K, reads like a veritable sales
brochure for UNIX"
-- http://www.theregister.co.uk/content/4/28226.html


             reply	other threads:[~2008-02-14 22:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-14 22:19 Erik de Castro Lopo [this message]
2008-02-15  6:47 ` [Caml-list] " Christophe Raffalli
2008-02-15  8:18 ` SerP

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=20080215091910.bb982431.mle+ocaml@mega-nerd.com \
    --to=mle+ocaml@mega-nerd.com \
    --cc=Caml-list@yquem.inria.fr \
    /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).