<semaphore.h> Library
Simple implementation of the semaphore library:
#include <semaphore.h>
sem_t mutex;
void *althernateBlink(void *value)
{
while (true)
{
sem_wait(&mutex);
// do something once the semaphore is greater than 0
}
return NULL;
}
void *lightShowLED(void *value)
{
while (true)
{
// do something
sem_post(&mutex);
}
return NULL;
}
int main()
{
pthread_t thread[4];
sem_init(&mutex, 0, 0);
pthread_create(&thread[0], NULL, &lightShowLED, NULL);
pthread_create(&thread[1], NULL, &althernateBlink, NULL);
return 0;
}Last updated