Example #1
0
/**
 * Starts 4 pthreads and uses either a pthread_rwlock_t or a di_rwlock_t
 * to protect access to an array.
 *
 */
int main(void) {
    int i;
    pthread_t *pthread_list;
    int numThreads = 0;
    int threadList[] = { 1, 2, 4, 8, 16, 24, 32, 48, 64, 128 }; // size is 10

    /* Allocate memory for the two instance arrays */
    array1 = (int *)malloc(ARRAY_SIZE*sizeof(int));
    if (array1 == NULL) {
        printf("Not enough memory to allocate array\n");
        return -1;
    }
    for (i = 0; i < ARRAY_SIZE; i++) array1[i] = 0;

    /* Initialize locks */
    pthread_mutex_init(&pmutex, NULL);
    ticket_mutex_init(&ticketmutex);
    tidex_mutex_init(&tidexmutex);

    printf("Starting benchmark with %d threads\n", NUM_THREADS);
    printf("Array has size of %d\n", ARRAY_SIZE);

    // Create the threads
    pthread_list = (pthread_t *)calloc(sizeof(pthread_t), NUM_THREADS);


    for (int i = 0; i < 10; i ++) {
        printf("\n---------- Active threads: %d ----------\n", threadList[i]);
        singleTest(threadList[i], "pthread_mutex_t, sleeping for 10 seconds...\n", TYPE_PTHREAD_MUTEX, pthread_list);
        singleTest(threadList[i], "ticket_mutex_t, sleeping for 10 seconds...\n",  TYPE_TICKET_MUTEX,  pthread_list);
        singleTest(threadList[i], "tidex_mutex_t, sleeping for 10 seconds...\n",   TYPE_TIDEX_MUTEX,   pthread_list);
    }

    /* Destroy locks */
    pthread_mutex_destroy(&pmutex);
    ticket_mutex_destroy(&ticketmutex);
    tidex_mutex_destroy(&tidexmutex);

    /* Release memory for the array instances and threads */
    free(array1);
    free(pthread_list);
    return 0;
}
 void
 run (Arg)
   {
     noOptions();
     help();
     groupID();
     singleTest();
     groupFilter1();
     groupFilter2();
     additionalCmd();
     additionalCmd2();
   }