STASIS
A pipeline delivery generator
Loading...
Searching...
No Matches
sem.h File Reference
#include "core.h"
#include <semaphore.h>
Include dependency graph for sem.h:

Go to the source code of this file.

Data Structures

struct  Semaphore
 

Functions

int semaphore_init (struct Semaphore *s, const char *name, int value)
 
int semaphore_wait (struct Semaphore *s)
 
int semaphore_post (struct Semaphore *s)
 
void semaphore_destroy (struct Semaphore *s)
 

Function Documentation

◆ semaphore_init()

int semaphore_init ( struct Semaphore * s,
const char * name,
int value )

Initialize a cross-platform semaphore (Linux/Darwin)

c
#include "sem.h"
int main(int argc, char *argv[]) {
struct Semaphore s;
if (semaphore_init(&s, "mysem", 1)) {
perror("semaphore_init failed");
exit(1);
}
if (semaphore_wait(&s)) {
perror("semaphore_wait failed");
exit(1);
}
//
// Critical section
// CODE HERE
//
if (semaphore_post(&s)) {
perror("semaphore_post failed");
exit(1);
}
semaphore_destroy(&s);
}
int semaphore_init(struct Semaphore *s, const char *name, int value)
Definition semaphore.c:33
Definition sem.h:15
Parameters
sa pointer to Semaphore
nameof the semaphore
valueinitial value of the semaphore
Returns
-1 on error
0 on success