caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: rixed@happyleptic.org
To: caml-list@inria.fr
Subject: [Caml-list] Unix.single_write, doc and atomicity
Date: Wed, 6 Jun 2012 15:06:46 +0200	[thread overview]
Message-ID: <20120606130646.GA23115@securactive.lan> (raw)

I was reading the code for unix_single_write recently, and noticed two strange
things that I prefer to discuss here before filling the bug tracker with
dubious tickets.

First, the doc of Unix.single_write claims that this function "attemps to write
only once", although the underlying unix_single_write C function clearly loops
around a write if the buffer being written is larger than the internal buffer
(16K).  So if one large buffer is written and an error happens after the first
16K then the written file is now corrupt. Looks like a bug. At the very least,
the documentation should state that single_write can write atomicaly only
buffer smaller than 16K. But I'd prefer a solution based on dynamic memory
allocation for the required iobuf.

Then, while we are on atomicity, another annoying thing: as the giant lock is
released during the write some other thread may perform another single_write on
the same file handler and again if the written buffers are larger than 16K the
simultaneous write loop may interleave the written chunks. In other words, the
nice atomicity properties of unix files opened with O_APPEND flag no longer
holds. Although the doc does not pretend that the writes will be atomic in this
situation, this is quite sad.

So this boils down to : unix_single_write really should perform a single write!
What do you think?


             reply	other threads:[~2012-06-06 13:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06 13:06 rixed [this message]
2012-06-06 13:17 ` Török Edwin
2012-06-06 13:29   ` oliver
2012-06-06 13:34   ` rixed
2012-06-16 23:11 ` Goswin von Brederlow

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=20120606130646.GA23115@securactive.lan \
    --to=rixed@happyleptic.org \
    --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).