Created
March 13, 2014 04:16
-
-
Save mayflaver/9521813 to your computer and use it in GitHub Desktop.
libuv async demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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