caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: osiire <osiire@k8.dion.ne.jp>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Are unreachable threads garbage collected?
Date: Sun, 04 Dec 2005 11:28:32 +0900	[thread overview]
Message-ID: <87iru5egtr.wl%osiire@k8.dion.ne.jp> (raw)
In-Reply-To: <20051204001629.39621.qmail@web34610.mail.mud.yahoo.com>


On Sat, 3 Dec 2005 16:16:29 -0800 (PST)
In <20051204001629.39621.qmail@web34610.mail.mud.yahoo.com>
Ker Lutyn <ker527mail@yahoo.com> wrote:
> Here's my reworking of this example to make the thread go away if the buffered
> channel becomes "unreachable". The strategy is to allocate the channel object
> at the very end and associate a Gc.finalise function with it that syncs an
> event on a kill channel with the thread.

> Does this look like a reasonable design pattern for this?

I think the strategy is reasonable. But the pattern can be more simple.

let make_gc_event v =
  let gc_channel = new_channel () in
  let gc_send () = sync (send gc_channel ()) in
  let finalise _ = ignore (Thread.create gc_send ()) in
  Gc.finalise finalise v;
  wrap (receive gc_channel)

usage is as follow:

  let bc = i, o in
  let gc = make_gc_event bc in
  let rec loop q =
    select [
      wrap (receive i) (fun x -> let ... in loop q);
      wrap (send o v) (fun _ -> loop q);
      gc (fun () -> Printf.printf "killed\n"; flush stdout; ())
    ]
  in
  ignore (Thread.create loop q);
  bc

----
 osiire


      reply	other threads:[~2005-12-04  2:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <ad8cfe7e0512031554g73aaf5f8w142196c4f9c939c0@mail.gmail.com>
2005-12-04  0:16 ` Ker Lutyn
2005-12-04  2:28   ` osiire [this message]

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=87iru5egtr.wl%osiire@k8.dion.ne.jp \
    --to=osiire@k8.dion.ne.jp \
    --cc=caml-list@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).