All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: linux-kernel@vger.kernel.org, bonachead@comcast.net, torvalds@osdl.org
Subject: Re: PROBLEM: pthread-safety bug in write(2) on Linux 2.6.x
Date: Thu, 27 Apr 2006 11:06:20 +0200	[thread overview]
Message-ID: <20060427090620.GF4649@implementation.labri.fr> (raw)

Hi,

I'm getting a bit late in the discussion, but this is a bug that we've
here known for quite some time now. The easy fix for getting correct
concurrent writes was to add a pipe: instead of calling

my_parallel_program > log

just call

my_parallel_program | tee log

the pipe guarantees atomicity.

Another testcase was the following program:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  int n, num = 0, lus = 0;
  char c;

  if(argc >= 2) num = atoi(argv[1]) - 1;

  while (num) {
    if(fork() == 0) break;
    num--;
  }

  for(;;) {
    n = read(STDIN_FILENO, &c, 1);
    if(n == 1) lus++;
    else break;
  }

  printf("Proc %d read %d bytes\n", num, lus);
  return 0;
}

Running it with no parameter runs fine:

$ ls -l foo
-rwxr-xr-x 1 samy samy 8174 2006-04-07 11:21 testlocale
$ ./lire < foo
Proc 0 read 8174 bytes

Running it with a given number of processes shows the non-atomicity of
offset update, even on UP:

$ ./lire 2 < foo
Proc 0 read 3903 bytes
Proc 1 read 8174 bytes

And it is getting worse as the number of processes increase. When we
discovered this, we checked such atomicity (i.e. each byte of the file
is read exactly by one process) on several systems:

- As shown, linux completely fails.
- OS X almost succeeds: on a dual SMP system, with 10 processes on a
900KB file, 68 bytes got read by more that one process.
- OSF succeeds: on a 8-way SMP system, with 10 processes on a 50MB
file, _no_ byte got read by more than one process.
- Solaris completely fails.
- AIX completely fails.

So I guess that people should just _not_ rely on such atomicity.

Regards,
Samuel

             reply	other threads:[~2006-04-27  9:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-27  9:06 Samuel Thibault [this message]
2006-04-27 15:23 ` PROBLEM: pthread-safety bug in write(2) on Linux 2.6.x Linus Torvalds
     [not found] <60Z8f-4QA-25@gated-at.bofh.it>
     [not found] ` <611Wl-u5-1@gated-at.bofh.it>
     [not found]   ` <616k2-6Xz-27@gated-at.bofh.it>
2006-04-14  9:14     ` Kai Henningsen
  -- strict thread matches above, loose matches on Subject: below --
2006-04-13  1:45 Dan Bonachea
2006-04-13  2:10 ` Alistair John Strachan
2006-04-13  4:46 ` Andrew Morton
2006-04-13  5:33   ` Nick Piggin
2006-04-13 15:01     ` Linus Torvalds
2006-04-13 15:28       ` Linus Torvalds
2006-04-14 10:20         ` Nikita Danilov
2006-04-13 21:50       ` Alan Cox
2006-04-13 22:06         ` Dan Bonachea
2006-04-13 23:03           ` Linus Torvalds
2006-04-13 23:11           ` Alan Cox
2006-04-13 23:19             ` Linus Torvalds
2006-04-13 22:40         ` Linus Torvalds
2006-04-13 23:05           ` Alan Cox
2006-04-13 23:06             ` Linus Torvalds
2006-04-13 23:11               ` Linus Torvalds
2006-04-13  9:18   ` Dan Bonachea
2006-04-13  9:56     ` Andrew Morton
2006-04-13 10:28       ` Kyle Moffett
2006-04-13 14:14     ` Jan Engelhardt
2010-12-19 22:45 ` Jens Moser

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=20060427090620.GF4649@implementation.labri.fr \
    --to=samuel.thibault@ens-lyon.org \
    --cc=bonachead@comcast.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.