Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created August 22, 2012 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piscisaureus/3427691 to your computer and use it in GitHub Desktop.
Save piscisaureus/3427691 to your computer and use it in GitHub Desktop.
test.c
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <assert.h>
#include <mach/mach_init.h>
#include <mach/task.h>
#include <mach/thread_act.h>
#include <mach/semaphore.h>
static semaphore_t sem;
void onsignal(int signum) {
fprintf(stdout, "signal: %d\n", signum);
}
int main() {
signal(SIGUSR1, onsignal);
semaphore_create(mach_task_self(), &sem, 0, 0);
fprintf(stdout, "wait!\n");
fprintf(stdout, "%d\n", semaphore_wait(sem));
fprintf(stdout, "wait end!\n");
semaphore_destroy(mach_task_self(), sem);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment