/* main */ int main(int argc, char *argv[]) { int threads = atoi(argv[5]); /* initialize rw lock */ struct rw *l = NULL; preference pref; /* populate struct */ struct opts *o = malloc(sizeof(struct opts)); o->wcslen = atoi(argv[1]); o->rcslen = atoi(argv[2]); o->ncslen = atoi(argv[3]); o->prob = atoi(argv[4]); o->array = calloc(64, sizeof(int)); o->msecs = atoi(argv[7]); switch (atoi(argv[6])) { case 0: pref = NEUTRAL; break; case 1: pref = READER; break; case 2: pref = WRITER; break; case 3: pref = READER_OPT; break; } o->lock = init_rw(pref); pthread_t *t = malloc(sizeof(pthread_t) * threads); for (int i = 0; i < threads; i++) pthread_create(&t[i], NULL, rw_bnchmrk, (void *)o); long ac = 0; void *status; for (int i = 0; i < threads; i++) { pthread_join(t[i], &status); ac += (long)status; } printf ("%ld\n",ac); destroy_rw(o->lock); free(t); free(o->array); free(o); return 0; }
int init_rw_dec(uint_fast8_t n) { // If sizeof(subset_t) * (1ul << n) overflows, it wraps around to 0, since size_t and unsigned long are unsigned integer types. if(n && !(sizeof(subset_t) * (1ul << n))) return(-1); if(init_rw(n)) return(-1); cslots = malloc(sizeof(subset_t) * (1ul << n)); return(cslots ? 0 : -1); }