sem_open really strange behavior
Andrew Haley
aph@redhat.com
Tue Jun 22 13:54:00 GMT 2010
On 06/22/2010 02:16 PM, Sergio Sobarzo wrote:
>
> I'm writing an application using semaphores. Here is a simple code
> recreating the problem:
>
> ***********************************************
> #include <sys/types.h>
> #include <stdio.h>
> #include <semaphore.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <stdlib.h>
>
> int main()
> {
> int ok;
> //key_t t;
> char *shm,*s;
> sem_t *mutex;
>
> mutex = sem_open("/vik",O_CREAT|O_EXCL);
> if(mutex == SEM_FAILED)
> {
> perror("unable to create semaphore");
> sem_unlink("vik");
> exit(-1);
> }
>
> sem_close(mutex);
> sem_unlink("vik");
> exit(0);
> }
> ************************************************
>
> This, is going to generate "unable to create semaphore: Invalid
> argument" no matter how many times I execute it. It is compiled with
> "gcc sem.c -lrt"
>
> However, once I uncomment the key_t line, everything works fine. What
> should be wrong? I'm stuck on this little thing for hours.
I'm sure this isn't a gcc problem. Maybe a bug in the library, or something?
Hard to say.
Andrew.
More information about the Gcc-help
mailing list