caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: caml-list@inria.fr
Cc: Zheng Li <li@pps.jussieu.fr>
Subject: Re: [Caml-list] [ANN] coThreads 0.10
Date: Tue, 18 Sep 2007 19:09:07 +1000	[thread overview]
Message-ID: <1190106547.24514.24.camel@rosella.wigram> (raw)
In-Reply-To: <20070918162347.e04ac421.mle+ocaml@mega-nerd.com>

On Tue, 2007-09-18 at 16:23 +1000, Erik de Castro Lopo wrote:
> skaller wrote:

> > It is not clear that a seek to an invalid position in the file
> > is going to succeed. It's also not clear to me that the seek
> > argument isn't 32 bits (depends on complex ugly GNU macro
> > hackery what type off_t is .. my Caml got built with
> > the LARGE_FILE macro thing so it should be 64 bits).
> 
> Shouldn't off_t always be 64 bits on a 64 bit CPU? 

I don't know. I traced through the code and did some debugging,
and the problem is that system wide mutex is emulated by using
locking on an lseek on a (deleted) lock file. The seek address
is a magic number which is rather large, and this appears to
cause the EINVAL errno on the lseek call.

let lock_fd = 
  print_endline "CREATING MUTEX";
  let lock_name = fresh_name "_mutex" in
  remove_exists lock_name; 
  let fd = openfile lock_name [O_WRONLY; O_CREAT] file_perm in
  remove_exists lock_name;
  fd

type t = int (* The offset *)

let create = fresh_number

let rec lock lk = 
  print_endline ("LOCK " ^ string_of_int lk);
  if lk <> lseek lock_fd lk SEEK_SET then assert false;
  lockf lock_fd F_LOCK 1

So basically a mutex is modelled by an offset,
which is created by fresh_number routine, and using
Unix discretionary locks with lockf function, which
is based on the current position in the file.

Well, I don't see how the lseek can fail unless there
is a filesize constraint somewhere detecting that

1695112678495748100

is an invalid offset for lseek. 

A possible patch is to take this in process.coordinator

(* fresh_number fresh_name ensure that there won't exist number/name
   confliction between running processes.
*)
let fresh_number =
  let usable_size = Sys.word_size -2 in
  let bits_of_id = 16 in (* Should be sufficient in most OS *)
  let bits_of_num = usable_size - bits_of_id in
  let counter = ref 0 in
  fun () ->
    let self_id = id (self ()) in
    let id_part = bit_chop_to_n bits_of_id self_id in
    let num_part = 
      counter := bit_chop_to_n bits_of_num (!counter + 1);
      !counter in
    (id_part lsl bits_of_num) + num_part


and use the line 2:

  let usable_size = 30 in

instead (though I didn't try it, some other places may need
to replace Sys.word_size the same way for it to work
properly).

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  parent reply	other threads:[~2007-09-18  9:08 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-17 16:31 Zheng Li
2007-09-17 16:48 ` Zheng Li
2007-09-17 17:39   ` [Caml-list] " skaller
2007-09-17 17:51     ` Zheng Li
2007-09-17 21:33       ` [Caml-list] " skaller
2007-09-17 22:37         ` Zheng Li
2007-09-17 23:26           ` [Caml-list] " skaller
2007-09-18  0:16             ` Zheng Li
2007-09-18  0:53   ` [Caml-list] " Erik de Castro Lopo
2007-09-18  1:25     ` Erik de Castro Lopo
2007-09-18  4:29     ` skaller
2007-09-19 10:11   ` Erik de Castro Lopo
2007-09-19 10:58     ` Can coThreads be used for message passing architecture? Jan Kybic
2007-09-19 11:13       ` [Caml-list] " Erik de Castro Lopo
2007-09-19 12:59         ` Zheng Li
2007-09-20  4:16         ` [Caml-list] " Jon Harrop
2007-09-20  6:11           ` Erik de Castro Lopo
2007-09-20  9:06             ` Zheng Li
2007-09-20  8:49           ` Zheng Li
2007-09-19 19:13   ` [Caml-list] Re: [ANN] coThreads 0.10 Vu Ngoc San
2007-09-19 20:10     ` Zheng Li
2007-09-20  0:50       ` [Caml-list] " skaller
2007-09-20  4:29         ` Erik de Castro Lopo
2007-09-20  7:11           ` skaller
2007-09-20  7:52             ` Erik de Castro Lopo
2007-09-20  8:37               ` Zheng Li
2007-09-20 10:43                 ` [Caml-list] " skaller
2007-09-20 10:44                   ` Matthew Hannigan
2007-09-20 15:02                     ` skaller
2007-09-20 15:07                       ` Christophe Raffalli
2007-09-20 15:51                         ` skaller
2007-09-20 16:26                       ` Florian Weimer
2007-09-20 17:37                         ` Vincent Aravantinos
2007-09-21 16:33                       ` readline license (was: [ANN] coThreads 0.10) Xavier Leroy
2007-09-21 17:11                         ` [Caml-list] " Matthew William Cox
2007-09-21 18:05                         ` skaller
2007-09-21 21:51                           ` [Caml-list] Re: readline license Markus E L
2007-09-21 22:16                             ` Daniel Bünzli
2007-09-22  0:49                           ` [Caml-list] Re: readline license (was: [ANN] coThreads 0.10) Matthew Hannigan
2007-09-20 11:39                   ` [Caml-list] Re: [ANN] coThreads 0.10 Florian Weimer
2007-09-20 15:46                     ` skaller
2007-09-20 18:14                       ` Ken Rose
2007-09-20  8:31           ` Zheng Li
2007-09-20  8:18         ` Zheng Li
2007-09-18  2:10 ` [Caml-list] " Erik de Castro Lopo
2007-09-18  5:59   ` skaller
2007-09-18  6:23     ` Erik de Castro Lopo
2007-09-18  9:01       ` Zheng Li
2007-09-18 13:40         ` Zheng Li
2007-09-18 23:53           ` [Caml-list] " Erik de Castro Lopo
2007-09-18  9:09       ` skaller [this message]
2007-09-18 13:03       ` [Caml-list] " Markus E L

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=1190106547.24514.24.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=li@pps.jussieu.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).