This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin 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]

sem.h, incompatible tipe for argument 4 of `semctl'


Hi,
I'm tring to use semaphores and I'm working with the patch named
'cygipc' found at the 'ported software' page at the cygin website.
I found an example on the net that seemed to me very easy. 

The problem is that I get the error:
semabinit.c:49: incompatible type for argument 4 of `semctl'
corresponding to the code line:
if( semctl(id, 0, SETVAL, argument) < 0)

I found on the net some hints to solve this problem, but they couldn't
help me. Can you?
I also attach the code.
Thank you,

Marcello


------------------------------------------------------------------
Unix semaphore example
/* semabinit.c - initialize a semaphore for use by programs sema and
semb */

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <stdio.h>

#define KEY (1492)

void main()
{
   int id; /* Number by which the semaphore is known within a program
*/

union semun {
int val;
struct semid_ds *buf;
ushort * array;
} argument;

   argument.val = 0;

   /* Create the semaphore with external key KEY if it doesn't already 
      exists. Give permissions to the world. */

   id = semget(KEY, 1, 0666 | IPC_CREAT);

   /* Always check system returns. */

   if(id < 0)
   {
      fprintf(stderr, "Unable to obtain semaphore. ");
      exit(0);
   }

   /* What we actually get is an array of semaphores. The second 
      argument to semget() was the array dimension - in our case
      1. */

   /* Set the value of the number 0 semaphore in semaphore array
      # id to the value 0. */

   if( semctl(id, 0, SETVAL, argument) < 0)
   {
      fprintf( stderr, "Cannot set semaphore value. ");
   }
   else
   {
      fprintf(stderr, "Semaphore %d initialized. ", KEY);
   }
}


=====
c:\>ptk




__________________________________________________

__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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