public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: <sten.kristian.ivarsson@gmail.com>
To: "'Ken Brown'" <kbrown@cornell.edu>
Cc: "'cygwin'" <cygwin@cygwin.com>
Subject: Sv: Sv: Sv: Named pipes and multiple writers
Date: Fri, 27 Mar 2020 15:53:36 +0100	[thread overview]
Message-ID: <00b901d60447$7ecb4c50$7c61e4f0$@gmail.com> (raw)
In-Reply-To: <b311d907-7376-5bc6-3216-7d2b96728dbc@cornell.edu>

[-- Attachment #1: Type: text/plain, Size: 1042 bytes --]

>On 3/26/2020 7:19 PM, Ken Brown via Cygwin wrote:
>> On 3/26/2020 6:39 PM, Ken Brown via Cygwin wrote:
>>> On 3/26/2020 6:01 PM, sten.kristian.ivarsson@gmail.com wrote:
>>>> The ENIXIO occurs when parallel child-processes simultaneously using 
>>>> O_NONBLOCK opening the descriptor.
>>>
>>> This is consistent with my guess that the error is generated by 
>>> fhandler_fifo::wait.  I have a feeling that read_ready should have 
>>> been created as a manual-reset event, and that more care is needed to 
>>> make sure it's set when it should be.
>>>
>>>> I could provide a code-snippet
>>>> to reproduce it if wanted ?
>>>
>>> Yes, please!
>> 
>> That might not be necessary.  If you're able to build the git repo 
>> master branch, please try the attached patch.

>Here's a better patch.


I finally succeeded to build latest master (make is not my favourite tool)
and added the patch, but still no success in my little test-program (see
attachment) when creating a write-file-descriptor with O_NONBLOCK

 
>Ken

[-- Attachment #2: pipe.cpp --]
[-- Type: text/plain, Size: 1671 bytes --]

#include <cstring>

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <iostream>
#include <string>

namespace
{
   auto error(const int error)
   {
      std::cerr << getpid() << "\terror:\t" << error << '\t' << std::strerror(error) << std::endl;
      return error;
   }
}

int main()
{
   const auto name{"/tmp/my_name"};

   const auto result = mkfifo(name, 0666);

   if(result) return error(errno);

   constexpr auto writers{5};
   constexpr auto messages{4};

   for(auto idx = 0; idx < writers; ++idx)
   {
      const auto pid = fork();

      if(pid < 0) return error(errno);

      if(pid == 0)
      {
         std::cout << "child " << getpid() << std::endl;
         for(auto idx = 0; idx < messages; ++idx)
         {
            const auto wfd = open(name, O_WRONLY | O_NONBLOCK);
            if(wfd < 0) return error(errno);
            const auto msg{std::to_string(getpid())};
            if(write(wfd, msg.data(), msg.size() + 1) < 0) error(errno);
            close(wfd);
         }
         return 0;
      }
   }

   {
      std::cout << "parent" << std::endl;

      const auto rfd = open(name, O_RDONLY);
      const auto wfd = open(name, O_WRONLY);
      if(rfd < 0) return error(errno);
      for(auto idx = 0; idx < writers * messages; ++idx)
      {
         std::string buffer;
         buffer.resize(80);
         if(read(rfd, &buffer[0], buffer.size()) < 0) error(errno);
         std::cout << buffer << std::endl;
      }
      close(wfd);
      close(rfd);
   }

   if(unlink(name) < 0) return error(errno);

   return 0;
}

  reply	other threads:[~2020-03-27 14:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25 11:11 sten.kristian.ivarsson
2020-03-25 12:44 ` Ken Brown
     [not found]   ` <18be01d602ab$0bbfca30$233f5e90$@gmail.com>
2020-03-26 14:06     ` Sv: " Ken Brown
2020-03-26 15:11       ` Ken Brown
2020-03-26 16:03         ` Norton Allen
2020-03-26 16:44           ` Ken Brown
2020-03-26 17:00             ` Norton Allen
2020-03-26 22:01       ` Sv: " sten.kristian.ivarsson
2020-03-26 22:39         ` Ken Brown
2020-03-26 23:19           ` Ken Brown
2020-03-27 13:10             ` Ken Brown
2020-03-27 14:53               ` sten.kristian.ivarsson [this message]
2020-03-27 22:56                 ` Sv: " Ken Brown
2020-03-27 23:00                   ` Ken Brown
2020-03-28 12:10                   ` Sv: " sten.kristian.ivarsson
2020-03-28 15:43                     ` Ken Brown
2020-03-29  2:19                       ` Ken Brown
2020-03-30 17:44                         ` Ken Brown
2020-03-31 21:10                           ` Sv: " sten.kristian.ivarsson
2020-03-31 22:02                             ` Ken Brown
2020-04-01  7:45                               ` Sv: " sten.kristian.ivarsson
2020-04-01 13:47                                 ` Ken Brown
2020-04-01  8:52                               ` sten.kristian.ivarsson
2020-04-01 16:15                                 ` Ken Brown
2020-04-01 17:14                                   ` Sv: " sten.kristian.ivarsson
2020-04-01 18:34                                     ` Ken Brown
2020-04-02  2:19                                       ` Ken Brown
2020-04-02  8:05                                         ` Sv: " sten.kristian.ivarsson
2020-04-02 12:47                                           ` Sv: Sv: Sv: Sv: Sv: Sv: Sv: Sv: Named pipes and multiple wri Gregery Barton
2020-04-02 18:21                                           ` Sv: Sv: Sv: Sv: Sv: Sv: Sv: Sv: Named pipes and multiple writers Ken Brown

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='00b901d60447$7ecb4c50$7c61e4f0$@gmail.com' \
    --to=sten.kristian.ivarsson@gmail.com \
    --cc=cygwin@cygwin.com \
    --cc=kbrown@cornell.edu \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).