Skip to content

Instantly share code, notes, and snippets.

@saghul
Created August 24, 2015 22:35
Show Gist options
  • Save saghul/34a36313154624fafa8e to your computer and use it in GitHub Desktop.
Save saghul/34a36313154624fafa8e to your computer and use it in GitHub Desktop.
#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