public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: Win32 error in C program using openmp and fork()
Date: Tue, 23 Jul 2013 14:39:00 -0000	[thread overview]
Message-ID: <20130723141855.GH9689@calimero.vinschen.de> (raw)
In-Reply-To: <20130723130851.GG9689@calimero.vinschen.de>

On Jul 23 15:08, Corinna Vinschen wrote:
> On Jul 23 13:28, Daniel Brown wrote:
> > and that still had the fork error. I have also tried running in safe
> > mode and
> > stopping all my anti-virus software just incase that was interfering
> > somehow.
> > So I get as an output now...
> > 
> > Daniel@XPS15z ~
> > $ uname -r
> > 1.7.22s(0.268/5/3)
> > 
> > Daniel@XPS15z ~
> > $ ./a.exe
> > I'm an openmp thread...
> > I'm an openmp thread...
> > I'm an openmp thread...
> > I'm an openmp thread...
> > Parent fork 1 [main] a 5832 C:\cygwin\home\Daniel\a.exe: *** fatal
> > error in forked process - failed
> > to create new win32 semaphore, currentvalue -2, Win32 error 87
> > 
> > However if I reduce the number of threads from 4 to 2 with:
> > 
> > #pragma omp parallel num_threads(2)
> > {
> > printf("I'm an openmp thread...\n");
> > }
> 
> Ah, now there's something different.  If I set the number of threads to
> 4, I can reproduce this problem almost every try with currentvalue -2,
> occassionally with currentvalue -1.
> 
> > Looking at the source in thread.cc _fixup_after_fork() the win32
> > error 87 is ERROR_INVALID_PARAMETER
> > which is due to currentvalue < 0.
> > 
> > My only guess is that there is a race condition on the
> > currentvalue-- operations perhaps?
> 
> Apparently.  I investigate...

Yes, there was a race condition in setting the value of the semaphore
private "currentvalue" member.  The only reason to keep track of the
value is to allow _fixup_after_fork to set the right value, but here the
race comes into play.  I redesigned this part so that it only sets
currentvalue once, right from fork itself, to propagate the correct
value to the child process.

I'm just building new 32 and 64 bit snapshots.  They should be available
on http://cygwin.com/snapshots/ in an hour at the latest.  Please give
it a try.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2013-07-23 14:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-20 21:26 Daniel Brown
2013-07-21  7:10 ` Larry Hall (Cygwin)
2013-07-22  9:26 ` Corinna Vinschen
2013-07-23 12:36   ` Daniel Brown
2013-07-23 13:15     ` Ken Brown
2013-07-23 14:19     ` Corinna Vinschen
2013-07-23 14:39       ` Corinna Vinschen [this message]
2013-07-23 15:13         ` Corinna Vinschen
2013-07-24 13:03           ` Daniel Brown
2013-07-24 13:04             ` Corinna Vinschen
2013-07-21 23:46 Daniel Brown
2013-07-23 14:22 Daniel 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=20130723141855.GH9689@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.com \
    /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).