/* Compile with gcc -fPIC -g -c -Wall lib.c; gcc -shared -Wl -o lib.so lib.o */ #include #include typedef void callback_t(void); callback_t* callback_fn; void *async_cb(void *dummy) { (*callback_fn)(); (*callback_fn)(); pthread_exit(NULL); } int callback(callback_t* cb_fn) { pthread_t thread; int rc; printf("In callback: creating thread\n"); callback_fn = cb_fn; rc = pthread_create(&thread, NULL, async_cb, (void *)NULL); if (rc) { printf("ERROR; return code from pthread_create() is %d\n", rc); return(-1); } return(0); }