This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: sem_open really strange behavior


Thanks a lot Andrew,

I read that paragraph thousand of times. However it is not an answer why it works if a line is commented or not. I cannot figure an acceptable explanation, that's why I thought it will be a gcc question.

On 22-06-2010 9:23, Andrew Bell wrote:
On Tue, Jun 22, 2010 at 8:16 AM, Sergio Sobarzo<ssobarzo@gmail.com> wrote:
Hi,

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);
}
************************************************
The man page for sem_open says that if you include O_CREAT as a flag
you must also provide the mode and value arguments.  Have you tried
that?

P.S. - This isn't a gcc issue - you should probably post this to a
general UNIX programming list.

Best,



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]