caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Are unreachable threads garbage collected?
@ 2005-12-03 23:47 Ker Lutyn
  0 siblings, 0 replies; only message in thread
From: Ker Lutyn @ 2005-12-03 23:47 UTC (permalink / raw)
  To: caml-list

>From Reppy's paper, an implementation of buffered channels translated to OCaml.
Note the internal thread to manage the state. If the buffered channel becomes
unreachable, will this thread be garbage collected?

module Buffered_channel = struct
  open Event
  type 'a t = 'a channel * 'a channel
  let make () =
    let i = new_channel () in
    let o = new_channel () in
    let rec loop = function
      | [], [] -> loop ([sync (receive i)], [])
      | (a :: aa) as aaa, bbb -> select [
	  wrap (receive i) (fun x -> loop (aaa, x :: bbb));
	  wrap (send o a) (fun () -> loop (aa, bbb))
	]
      | [], bbb -> loop (List.rev bbb, [])
    in ignore (Thread.create loop ([], [])); (i, o)
  let send (i, _) x = Event.send i x
  let receive (_, o) = Event.receive o
end



		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-12-03 23:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-03 23:47 Are unreachable threads garbage collected? Ker Lutyn

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).