[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Semafor-arrays



Sådan.........

void do_semop( int hvem)
{
 struct sembuf sb[2];    /* vælger DOWN på 2 semaphorer */

 sb[0].sem_num = (hvem + 1) % count;
 sb[0].sem_op = -1;
 sb[0].sem_flg = SEM_UNDO;

 sb[1].sem_num = hvem;
 sb[1].sem_op = -1;
 sb[1].sem_flg = SEM_UNDO;

 /* nap dem begge eller vent... */
 if( semop( sem, sb, 2 ) == -1 )
  fprintf( stderr, "semop fejl: %s (hvem=%d)\n", strerror( errno ), hvem );
}

Mvh.

Christian

----- Original Message -----
From: "Claus Meldgaard Rasmussen" <sslug@sslug>
To: <sslug@sslug>
Sent: Tuesday, October 17, 2000 12:36 PM
Subject: [CPROG] Semafor-arrays


> Jeg arbejder med et array af semaforer oprettet med
>
> semId = semget(key_t)1234, X, 0666 | IPC_CREAT);
>
> hvor X repræsenterer antallet af semaforer under det pågældende semId.
>
> Mit problem er nu, hvordan jeg i én atomisk proces kan sætte værdien for
> to (eller evt. flere) af X semaforer.
> For at sætte værdien på ét semafor bruger jeg kommandoen semop således:
>
> struct sembuf semaphore;
>
> semaphore.sem_num = X;    file://X = semafor-nummeret
> semaphore.sem_op = -1;
> semaphore.sem_flg = SEM_UNDO;
>
> semop(semId, &semaphore, 1);
>
> Er der nogen der ved hvordan man tilgår flere semaforer ad gangen med ét
> kald af semop eller måske vha. semctl.
> MAN-siderne giver ikke meget svar på arbejdet med semafor-arrays, f.eks.
> heller ikke hvordan man modtager arrayet med de enkelte semaforers
> værdier med semctl(semId, X, GETALL, arg), hvor arg er af typen:
>
> union semun {
>     int val;
>     struct semid_ds *buf;
>     unsigned short *array;
> } arg;
>
> ligesom det heller ikke er muligt at få en forklaring af de enkelte
> medlemmer af semun.
>
> Jeg håber nogen kan overskue mit problem og hjælpe!
> Mvh.
> Claus
>



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *