~aritra1911/pthreads

859b323bc73be136bba5770f2226a1ccaa5583ad — Aritra Sarkar 2 years ago 0cc2f00 master
Fix some stuff that clang -Weverything was bitching about
4 files changed, 15 insertions(+), 18 deletions(-)

M cvsimple.c
M llist_threads.c
M llist_threads.h
M llist_threads_demo.c
M cvsimple.c => cvsimple.c +4 -7
@@ 4,14 4,14 @@

#define TCOUNT 10
#define WATCH_COUNT 12
#define INC_DELAY 1    /* useconds_t */
#define INC_DELAY 1 /* useconds_t */

void *watch_count(void *arg);
void *inc_count(void *arg);

int count = 0;
pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t count_threshold_cv = PTHREAD_COND_INITIALIZER;
static int count = 0;
static pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t count_threshold_cv = PTHREAD_COND_INITIALIZER;

extern int
main(void)


@@ 20,9 20,6 @@ main(void)
    int thread_ids[3] = { 0, 1, 2, };
    pthread_t threads[3];

    pthread_mutex_init(&count_mutex, NULL);
    pthread_cond_init(&count_threshold_cv, NULL);

    pthread_create(&threads[0], NULL, inc_count, (void *) &thread_ids[0]);
    pthread_create(&threads[1], NULL, inc_count, (void *) &thread_ids[1]);
    pthread_create(&threads[2], NULL, watch_count, (void *) &thread_ids[2]);

M llist_threads.c => llist_threads.c +1 -1
@@ 20,7 20,7 @@ int llist_init(llist_t *llistp)
    return 0;
}

int llist_insert_data(int index, void *datap, llist_t *llistp)
int llist_insert_data(size_t index, void *datap, llist_t *llistp)
{
    llist_node_t *cur, *prev, *new;
    int found = FALSE;

M llist_threads.h => llist_threads.h +5 -5
@@ 3,7 3,7 @@
#include <pthread.h>

typedef struct llist_node {
    int                 index;
    size_t              index;
    void                *datap;
    struct llist_node   *nextp;
} llist_node_t;


@@ 14,8 14,8 @@ typedef struct llist {
} llist_t;

int llist_init(llist_t *llistp);
int llist_insert_data(int index, void *datap, llist_t *llistp);
int llist_remove_data(int index, void **datapp, llist_t *llistp);
int llist_find_data(int index, void **datapp, llist_t *llistp);
int llist_change_data(int index, void *datap, llist_t *llistp);
int llist_insert_data(size_t index, void *datap, llist_t *llistp);
int llist_remove_data(size_t index, void **datapp, llist_t *llistp);
int llist_find_data(size_t index, void **datapp, llist_t *llistp);
int llist_change_data(size_t index, void *datap, llist_t *llistp);
int llist_show(llist_t *llistp, void (*show_item)(const void *));

M llist_threads_demo.c => llist_threads_demo.c +5 -5
@@ 41,7 41,7 @@ int main(void)

    printf("INFO : Populating array with %i items.\n", NUM_ITEMS);
    for (size_t i = 0; i < NUM_ITEMS; i++) {
        items[i] = drand48() * MAX_ITEM;
        items[i] = (int) (drand48() * (double) MAX_ITEM);
    }

    printf("INFO : Dispatching %i threads for insertion into linked list.\n",


@@ 94,8 94,8 @@ void shuffle(size_t *arr, size_t nitems, size_t ntimes)
    srand48(time_now.tv_nsec);

    for (size_t i = 0; i < ntimes; i++) {
        size_t idx = drand48() * nitems;
        int temp = arr[idx];
        size_t idx = (size_t) (drand48() * (double) nitems);
        size_t temp = arr[idx];
        arr[idx] = arr[nitems - idx - 1];
        arr[nitems - idx - 1] = temp;
    }


@@ 120,7 120,7 @@ void *insert_items(void *arg)
               args->tid, args->items[i], indexes[i]);
        llist_insert_data(indexes[i], (void *) &args->items[i], args->llistp);

        useconds_t delay = drand48() * MAX_DELAY;
        useconds_t delay = (useconds_t) (drand48() * (double) MAX_DELAY);
        printf("INFO : [THREAD #%03lu] Delaying insertion of next item by "
               "%uus.\n", args->tid, delay);
        usleep(delay);


@@ 133,5 133,5 @@ void *insert_items(void *arg)

void print_item(const void *item)
{
    printf("%i -> ", *(int *) item);
    printf("%i -> ", *(const int *) item);
}