From: Janne Hellsten <janne@hybrid.fi>
To: unlisted-recipients: ;(no To-header on input)
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] interprocess mutex
Date: Wed, 16 Feb 2005 21:59:41 +0200 [thread overview]
Message-ID: <4213A62D.3080803@hybrid.fi> (raw)
In-Reply-To: <421399A9.8040206@barettadeit.com>
OK, this is what I came up with (uses ExtLib's Std.finally):
---
let create_lock name =
let chnl = open_out name in
output_string chnl "Lockfile - don't delete";
close_out chnl
let with_write_block name f =
if not (Sys.file_exists name) then
create_lock name;
let fd = Unix.openfile name [Unix.O_RDWR] 0o660 in
Std.finally
(fun () -> Unix.close fd)
(fun _ ->
Unix.lockf fd Unix.F_LOCK 0;
f ()) ()
let test =
with_write_block "lock_name" (fun () -> Printf.printf "this code
blocks if other process already acquired lock!")
---
I hope I'm using lockf correctly.
Thanks for the help!
Best regards,
Janne
Alex Baretta wrote:
> Janne Hellsten wrote:
>
>> Hello,
>>
>> I need to sequentialize two processes accessing the same GDBM
>> database (OCaml's dbm library). Since GDBM allows for only one
>> writer at a time, I need a way to block until the previous writer has
>> finished. I think there is a way to do this with the original GDBM
>> library since it claims to handle the file lockings properly -- I
>> could block based on the returned error codes. However, this
>> functionality does not appear to be exposed through the Dbm module.
>>
>> Of course I can implement this blocking myself with an interprocess
>> mutex. But how can I implement such a mutex in OCaml? I couldn't
>> find anything from the standard library that would resemble my problem.
>
>
> Unix.lockf is the way to go.
>
> Alex
>
next prev parent reply other threads:[~2005-02-16 19:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-16 18:49 Janne Hellsten
2005-02-16 19:06 ` [Caml-list] " Alex Baretta
2005-02-16 19:59 ` Janne Hellsten [this message]
2005-02-16 19:37 ` Frédéric Gava
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=4213A62D.3080803@hybrid.fi \
--to=janne@hybrid.fi \
--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