#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--;