Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Parallel Processing ProgramsRSS Feeds

PROGRAM OF CREATE HEADER FILE FOR SEMAPHORE

Posted By: William Bouchard     Category: C Programming     Views: 6395

PROGRAM OF CREATE HEADER FILE FOR SEMAPHORE.

Code for PROGRAM OF CREATE HEADER FILE FOR SEMAPHORE in C Programming

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

void lock_init(int *lock1)
{
    union semun
    {
            int val;
            struct semid_ds *xx;
            ushort **yy;
    }arg;
    int j;
        j=semget(144,1,0666|IPC_CREAT);
        *lock1=j;
        arg.val=1;
        semctl(*lock1,0,SETVAL,arg);
}

void locksem(int *lock1)
{
      struct sembuf oprations;
          oprations.sem_num=0;
          oprations.sem_op=-1;
          oprations.sem_flg=0;
          semop(*lock1,&oprations,1);

}

void unlock(int *lock1)
{
        struct sembuf oprations;
        oprations.sem_num=0;
        oprations.sem_op=1;
        oprations.sem_flg=0;
        semop(*lock1,&oprations,1);
}

/*void free_sem(int id)
{
if(semctl(*id,1,IPC_RMID)!=0)
error_exit("cleanup_sem","semctl");
}
*/
  
Share: 


Didn't find what you were looking for? Find more on PROGRAM OF CREATE HEADER FILE FOR SEMAPHORE Or get search suggestion and latest updates.

William Bouchard
William Bouchard author of PROGRAM OF CREATE HEADER FILE FOR SEMAPHORE is from Montreal, Canada.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!