Skip to content

Instantly share code, notes, and snippets.

@postwait
Created December 30, 2013 19:28
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 postwait/8186779 to your computer and use it in GitHub Desktop.
Save postwait/8186779 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <port.h>
#include <sys/lwp.h>
#include <pthread.h>
lwpid_t other = 0;
int port_fd = -1;
void *thr_port_get(void *unused;) {
uint_t nget = 1;
port_event_t ev;
other = _lwp_self();
port_fd = port_create();
if(port_fd < 0) {
fprintf(stderr, "Failed to port_create()\n");
exit(-1);
}
port_getn(port_fd, &ev, 1, &nget, NULL);
fprintf(stderr, "Exiting... problem.\n");
exit(-1);
}
void stop_n_close(int sig) {
_lwp_suspend(other);
close(port_fd);
kill(getpid(), sig);
}
int main() {
pthread_t tid;
pthread_create(&tid, NULL, thr_port_get, NULL);
sleep(1);
signal(SIGSEGV, stop_n_close);
kill(getpid(), SIGSEGV);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment