Пример #1
0
/*
 * Thread start routine that issues work queue requests.
 */
void *thread_routine (void *arg)
{
    power_t *element;
    int count;
    unsigned int seed = (unsigned int)time (NULL);
    int status;

    /*
     * Loop, making requests.
     */
    for (count = 0; count < ITERATIONS; count++) {
        element = (power_t*)malloc (sizeof (power_t));
        if (element == NULL)
            errno_abort ("Allocate element");
        element->value = rand_r (&seed) % 20;
        element->power = rand_r (&seed) % 7;
        DPRINTF ((
            "Request: %d^%d\n",
            element->value, element->power));
        status = workq_add (&workq, (void*)element);
        if (status != 0)
            err_abort (status, "Add to work queue");
        sleep (rand_r (&seed) % 5);
    }
    return NULL;
}
Пример #2
0
void* thread_routine(void* arg)
{
    power_t* element;
    int count;
    unsigned int seed = (unsigned int)time(NULL);
    int status;

    for (count = 0; count < ITERATIONS; count++)
    {
        element = (power_t*)malloc(sizeof(power_t));
        assert(element != NULL);

        element->value = rand_r(&seed) % 20;
        element->power = rand_r(&seed) % 7;
        printf("Request: %d^%d\n", element->value, element->power);
        status = workq_add(&workq, (void*)element);
        assert(status == 0);
        sleep(rand_r(&seed) % 5);
    }

    return NULL;
}