Skip to content

Instantly share code, notes, and snippets.

@aerodame
Last active February 1, 2025 23:30
Show Gist options
  • Save aerodame/9a8f79ca18609d9790099e3dfecab34e to your computer and use it in GitHub Desktop.
Save aerodame/9a8f79ca18609d9790099e3dfecab34e to your computer and use it in GitHub Desktop.
#include "SimpleSemaphore.h"
Semaphore::Semaphore(int initialValue) : S(initialValue) {}
void Semaphore::P() {
while (S <= 0) {
// Busy wait (not ideal for real-world scenarios)
}
S--;
}
void Semaphore::V() {
S++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment