delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/03/12/12:06:32

X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: missing shm_open and shm_unlink
X-Mailer: Lotus Notes Release 5.0.13 March 9, 2004
Message-ID: <OFF82E785E.4F5B67E9-ON8825729C.005F50DC-8825729C.00636538@vtech.com>
From: Don Marquardt <DonMarquardt AT vtech DOT ca>
Date: Mon, 12 Mar 2007 10:05:33 -0800
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id l2CH6Jh6025267


I am building an application that will used shared memory and I have tried 
to compile the attached source file. I have version 3.4.4-3 of the gcc 
compiler and appropriate support libraries. 

If I use a simple gcc command it complains 

$ gcc -Wall -Werror writer.c
writer.c: In function `main':
writer.c:34: warning: implicit declaration of function `shm_open'
writer.c:85: warning: implicit declaration of function `shm_unlink'

-------------------------------------------------------  Source file 
-----------------------------------------------------
/*
** These examples use semaphores to ensure that writer and reader
** processes have exclusive, alternating access to the shared-memory 
region.
*/

/**********  writer.c  ***********/

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <semaphore.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/fcntl.h>

char shm_fn[] = "my_shm";
char sem_fn[] = "my_sem";

/**** WRITER ****/

int main(){
  caddr_t shmptr;
  unsigned int mode;
  int shmdes, index;
  sem_t *semdes;
  int SHM_SIZE;

  mode = S_IRWXU|S_IRWXG;

  /* Open the shared memory object */

  if ( (shmdes = shm_open(shm_fn,O_CREAT|O_RDWR|O_TRUNC, mode)) == -1 ) {
     printf("shm_open failure");
     exit(1);
   }

  /* Preallocate a shared memory area */

  SHM_SIZE = 4096;

  if(ftruncate(shmdes, SHM_SIZE) == -1){
    printf("ftruncate failure");
    exit(1);
  }

  if((shmptr = mmap(0, SHM_SIZE, PROT_WRITE|PROT_READ, MAP_SHARED,
                shmdes,0)) == (caddr_t) -1){
    printf("mmap failure");
    exit(1);
  }

  /* Create a semaphore in locked state */

 semdes = sem_open(sem_fn, O_CREAT, 0644, 0);

 if(semdes == (void*)-1){
   printf("sem_open failure");
   exit(1);
 }

    /* Access to the shared memory area */

    for(index = 0; index < 100; index++){
       printf("write %d into the shared memory shmptr[%d]\n", index*2, index);
       shmptr[index]=index*2;
       }

  /* Release the semaphore lock */

  sem_post(semdes);
  munmap(shmptr, SHM_SIZE);

  /* Close the shared memory object */

  close(shmdes);

  /* Close the Semaphore */

  sem_close(semdes);

  /* Delete the shared memory object */

  shm_unlink(shm_fn);
  exit(0);
  return 0;
}

-------------------------------------------------------  End Source file 
-----------------------------------------------------

I tried searching for shm_open in my version of the /cygwin/usr/include 
directory and did not find either the shm_open or shm_unlink prototypes 
defined.

In looking through the FAQ I came across this link

http://cygwin.com/ml/cygwin-cvs/2007-q1/msg00071.html

which suggests to me that I need an update on my header files and perhaps 
the dll. Is this update available now and if not, when will it be? How do 
I acquire these changes?


Thanks 

Don Marquardt
604 273 5131 X 810

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019