Example #1
0
void *bad(void *arg)
{
    while(1)
    {
        int err;
        int i = (int)arg;

        for(i=-1; i<MAX_MISBEHAVE; i++)
        {
            lprintf("calling misbehave(%d)", i);
        
            mutex_lock(&lock_print);
            expect(set_cursor_pos(24, 73));
            printf("% .2d", i);
            mutex_unlock(&lock_print);

            misbehave(i);
            sleep(bad_sleep);
        }
    }
    return arg;
}
Example #2
0
int main(int argc, char **argv)
{
    int n_levels;
    int ret;
    int i, rep;
    int misbehave_num;

    if (argc != 5) {
        printf("Wrong number of args.\n\n");
        print_usage(argv[0]);
        return -1;
    }

    n_levels = atoi(argv[1]);
    n_throws = atoi(argv[2]);
    rep = atoi(argv[3]);
    misbehave_num = atoi(argv[4]) - 1;

    if (n_levels < 0) {
        printf("Levels must be non-negative.\n\n");
        print_usage(argv[0]);
        return -1;
    }

    if (n_throws < 0) {
        printf("Throws must be non-negative.\n\n");
        print_usage(argv[0]);
        return -1;
    }

    if (thr_init(4096) != 0) {
        printf("Init failed. Something's busted.\n\n");
        return -10;
    }

    printf("MISBEHAVE: %d\n\n", misbehave_num);
    misbehave(misbehave_num);

    if (mutex_init(&count_mutex) != 0) {
        printf("Mutex init of count_mutex failed. Go fix your mutexes.\n\n");
        return -20;
    }

    
    for (i = 0; rep == 0 || i < rep; i++) {
        printf("Here we go! Repetition %d\n", i+1);

        if ((ret = (int)juggle((void *)n_levels)) != n_levels) {
     printf("Root juggle thread returned wrong value: %d should've been: %d\n",
                      ret, n_levels);
            return -2;
        }
        printf("\n\nSuccess. All balls accounted for.\n");

#ifdef COUNT_THREADS
        lprintf("Created and destroyed %d threads so far.\n", th_count);
#endif
    }

    thr_exit(0);
    printf("This is NOT happening!\n");
    return -30;
}