Sha256: cb28c593ad3ea5bec5a7c94fb6f7c9a0beeaf473ed7145031846c31e93118375

Contents?: true

Size: 796 Bytes

Versions: 15

Compression:

Stored size: 796 Bytes

Contents

#include <stdio.h>
#include <unistd.h>

#include <uv.h>

void hare(void *arg) {
    int tracklen = *((int *) arg);
    while (tracklen) {
        tracklen--;
        sleep(1);
        fprintf(stderr, "Hare ran another step\n");
    }
    fprintf(stderr, "Hare done running!\n");
}

void tortoise(void *arg) {
    int tracklen = *((int *) arg);
    while (tracklen) {
        tracklen--;
        fprintf(stderr, "Tortoise ran another step\n");
        sleep(3);
    }
    fprintf(stderr, "Tortoise done running!\n");
}

int main() {
    int tracklen = 10;
    uv_thread_t hare_id;
    uv_thread_t tortoise_id;
    uv_thread_create(&hare_id, hare, &tracklen);
    uv_thread_create(&tortoise_id, tortoise, &tracklen);

    uv_thread_join(&hare_id);
    uv_thread_join(&tortoise_id);
    return 0;
}

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
mt-libuv-4.1.04 ext/libuv/docs/code/thread-create/main.c
mt-libuv-4.1.03 ext/libuv/docs/code/thread-create/main.c
mt-libuv-4.1.02 ext/libuv/docs/code/thread-create/main.c
libuv-4.0.9 ext/libuv/docs/code/thread-create/main.c
libuv-4.0.2 ext/libuv/docs/code/thread-create/main.c
libuv-4.0.1 ext/libuv/docs/code/thread-create/main.c
libuv-4.0.0 ext/libuv/docs/code/thread-create/main.c
libuv-3.3.0 ext/libuv/docs/code/thread-create/main.c
libuv-3.2.4 ext/libuv/docs/code/thread-create/main.c
libuv-3.2.3 ext/libuv/docs/code/thread-create/main.c
libuv-3.2.2 ext/libuv/docs/code/thread-create/main.c
libuv-3.2.1 ext/libuv/docs/code/thread-create/main.c
libuv-3.2.0 ext/libuv/docs/code/thread-create/main.c
libuv-3.1.9 ext/libuv/docs/code/thread-create/main.c
libuv-3.1.8 ext/libuv/docs/code/thread-create/main.c