caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Unix.single_write, doc and atomicity
@ 2012-06-06 13:06 rixed
  2012-06-06 13:17 ` Török Edwin
  2012-06-16 23:11 ` Goswin von Brederlow
  0 siblings, 2 replies; 5+ messages in thread
From: rixed @ 2012-06-06 13:06 UTC (permalink / raw)
  To: caml-list

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?


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-06-16 23:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-06 13:06 [Caml-list] Unix.single_write, doc and atomicity rixed
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

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