#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>

typedef struct {
    char* s;
    long ns;
} par_t;

void check(int error) {
    if (error != 0) {
        fprintf(stderr, "Error: %s\n", strerror(error));
        exit(EXIT_FAILURE);
    }
}

void* print(void* p) {
    par_t* pp = p;
    struct timespec ts = {0, pp->ns};
    int i;
    for (i = 0; i < 10; i++) {
        nanosleep(&ts, NULL);
        printf(pp->s);
    }
    return NULL;
}

int main(void) {
    pthread_t t1, t2;

    par_t p1 = {"print1\n", 10000000}, p2 = {"print2\n", 20000000};

    check( pthread_create(&t1, NULL, &print, &p1) );
    check( pthread_create(&t2, NULL, &print, &p2) );

    check( pthread_join(t1, NULL) );
    check( pthread_join(t2, NULL) );

    return EXIT_SUCCESS;
}
