예제 #1
0
int main(int argc, char **argv)
{
    ta_libinit();

    int i;
    shared_data_t shared_data;
    srandom(time(NULL));

    memset(&shared_data, 0, sizeof(shared_data_t));
    for (i = 0 ; i < BUFFERSIZE; i++)
    {
        shared_data.buffer[i] = 0xFEEDFEED;
    }

    ta_sem_init(&shared_data.emptyBuffer, BUFFERSIZE);
    ta_sem_init(&shared_data.fullBuffer, 0);

    ta_create(killerthr, (void *)&shared_data);
    for ( i = 0; i < NPRODUCER; i++)
    {
	ta_create(producer, (void *)&shared_data);
    }

    for ( i = 0; i < NCONSUMER; i++)
    {
	ta_create(consumer, (void *)&shared_data);
    }


    int rv = ta_waitall();
    assert(rv == 0);

    return 0;
}
예제 #2
0
int main(int argc, char **argv)
{
    printf("Tester for stage 1.  Uses all four stage 1 library functions.\n");

    ta_libinit();

    int i = 0;
    for (i = 0; i < 2; i++) {
        ta_create(thread1, (void *)&i);
        ta_create(thread2, (void *)&i);
    }

    int rv = ta_waitall();
    if (rv) {
        fprintf(stderr, "%d threads were not ready to run when ta_waitall() was called\n", -rv);
    }
    return 0;
}
예제 #3
0
int main(int argc, char **argv)
{
    ta_libinit();

    ta_lock_init(&mutex);
    ta_cond_init(&condv);

    ta_create(thread1, NULL);
    ta_create(thread2, NULL);

    int rv = ta_waitall();
    assert(rv == 0);
    assert(value == 42);

    ta_lock_destroy(&mutex);
    ta_cond_destroy(&condv);

    return 0;
}