package
0.0.0-20241120161739-ebe831b73250
Repository: https://github.com/adrian-lin-1-0-0/go-study.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
# README
Semaphore
Binary Semaphores
int S = 1;
void wait() {
while (S <= 0);
S--;
}
void signal() {
S++;
}
Counting Semaphores
typedef struct {
int value;
struct process *list;
} semaphore;
void wait(semaphore *s) {
s->value--;
if (s->value < 0) {
block(s->list);
}
}
void signal(semaphore *s) {
s->value++;
if (s->value <= 0) {
wakeup(s->list);
}
}