Skip to content

Instantly share code, notes, and snippets.

@mayflaver
Created March 13, 2014 04:16
Show Gist options
  • Save mayflaver/9521813 to your computer and use it in GitHub Desktop.
Save mayflaver/9521813 to your computer and use it in GitHub Desktop.
libuv async demo
#include <uv.h>
#include <stdio.h>
#include <unistd.h>
uv_loop_t *loop;
uv_async_t async;
void print_progress(uv_async_t *handle, int status /*UNUSED*/) {
printf("%s\n", (char *)handle->data);
}
void deal(void *data) {
loop = uv_default_loop();
uv_async_init(loop, &async, print_progress);
printf("ok\n");
uv_run(loop, UV_RUN_NOWAIT);
return;
}
int main(int argc, char *argv[])
{
uv_thread_t hare_id;
uv_thread_create(&hare_id, deal, &async);
async.data = "hello world\n";
uv_async_send(&async);
printf("send\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment