Win32 error in C program using openmp and fork()

Daniel Brown ddb@star.sr.bham.ac.uk
Tue Jul 23 12:36:00 GMT 2013


I've wiped my old version of Cygwin and installed it fresh on my computer
and 1.7.21 doesn't work for me, either 32 or 64 bit. I have tried a Win 
7 x86
virtual machine and it worked, on a Win 8 x86 virtual machine though I see
the same error. Therefore I guess it is a Windows 8 issue unless you are
running it?

I tried replacing the cygwin1.dll with the latest snapshots 1.7.22s x86
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");
}

it works fine, if I use 3 threads then the error comes back. 
Interestingly the the value of currentvalue
changes each time I run the program if I use 4 or more threads, if I use 
3 then it is always -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?

Thanks,
Daniel

On 22/07/2013 09:06, Corinna Vinschen wrote:
> On Jul 20 19:30, Daniel Brown wrote:
>> Hi,
>>
>> So I have some code I am trying to port to Cygwin but I am getting the
>> error:
>>
>> fatal error in forked process - failed to create new win32 semaphore,
>> Win32 error 87
>>
>> when calling fork() in a C program when openmp code has been used
>> beforehand. I've got the following test code which reduces the problem
>> down to as little code as I could:
>>
>> #include <stdio.h>
>> #include <omp.h>
>> #include <sys/types.h>
>>
>> int main(void)
>> {
>>       pid_t childPID;
>>
>>       #pragma omp parallel
>>       {
>>           printf("I'm an openmp thread...\n");
>>       }
>>
>>       childPID =3D fork();
>>
>>       if(childPID >=3D 0) {
>>           if(childPID =3D=3D 0) {
>>               printf("Child fork\n");
>>           } else {
>>               printf("Parent fork\n");
>>           }
>>       } else {
>>           printf("Fork failed");
>>           return 1;
>>       }
>>
>>       return 0;
>> }
>>
>> To build I just use "gcc -fopenmp para.c" and the output I get is...
>>
>> I'm an openmp thread...
>> I'm an openmp thread...
>> I'm an openmp thread...
>> I'm an openmp thread...
>> Parent fork 0 [main] a 18640 D:\usr\code\c\a.exe: *** fatal error
>> in forked process - failed to create new win32 semaphore, Win32 error
>> 87
> I didn't try with 1.7.20, but with the current 1.7.21 and with the
> latest snapshot from http://cygwin.com/snapshots/, on 32 and 64 bit,
> and this is what I get on both cases:
>
>    $ uname -r
>    1.7.21(0.267/5/3)
>    $ gcc -g -fopenmp -o openmp-test openmp-test.c
>    $ ./openmp-test
>    I'm an openmp thread...
>    I'm an openmp thread...
>    Parent fork
>    Child fork
>    $
>
>
> Corinna
>


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



More information about the Cygwin mailing list