Decrement the value when a Process (进程)/Thread running - sem_wait(&semaphore);
Increase the value when a Process (进程)/Thread finishes running - sem_post(&semaphore);
#include <semaphore.h>int main() { sem_t semaphore; // 0 means it is not shared with other processes, 1 means only 1 thread can run at a time sem_init(&semaphore, 0, 1); sem_wait(&semaphore); // semmaphore-- sem_post(&semaphore); // semmaphore++ sem_destroy(&semaphore); return 0;}