Created
August 24, 2015 22:35
-
-
Save saghul/34a36313154624fafa8e to your computer and use it in GitHub Desktop.
This file contains 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 <assert.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <uv.h> | |
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) | |
#define NUM_JOBS 50 | |
#define SLEEP_MS 500 | |
static void | |
work_cb(uv_work_t* req) { | |
printf("Thread %d\n", (int)uv_thread_self()); | |
usleep(SLEEP_MS * 1000); | |
} | |
int main(int argc, char *argv[]) { | |
int i, r; | |
uv_work_t* reqs; | |
reqs = malloc(sizeof(*reqs) * NUM_JOBS); | |
assert(reqs != NULL); | |
for (i = 0; i < NUM_JOBS; i++) { | |
r = uv_queue_work(uv_default_loop(), &reqs[i], work_cb, NULL); | |
assert(r == 0); | |
} | |
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); | |
assert(r == 0); | |
free(reqs); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment