/*
* Simple semaphore implementation, P() and V().
*
- * Copyright (C) 2011-2013 Simon Ruderich
+ * Copyright (C) 2011-2014 Simon Ruderich
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "sem.h"
-#include <stdlib.h>
#include <pthread.h>
+#include <stdlib.h>
struct SEM {
void P(SEM *sem) {
pthread_mutex_lock(&sem->mutex);
- while (sem->value == 0) {
+ while (sem->value <= 0) {
pthread_cond_wait(&sem->condition, &sem->mutex);
}
sem->value--;