static void initbyuserid(const char *filename, const char *mode, int locktype, const char userid[USERID_MAXLEN], int access, FILE **file_r, int *initial_r, int *n_r) { FILE *file; int n,i; struct stat ustab; u32 hash; file= fopen(filename,mode); if (!file) ohshite("User database file `%s' inaccessible",filename); makelock(file,locktype,filename); if (fstat(fileno(file),&ustab)) ohshite("User database `%s' unstattable",filename); if (ustab.st_size % sizeof(struct userentry)) ohshit("User database `%s' corrupt",filename); n= ustab.st_size / sizeof(struct userentry); if (n==0) ohshit("User database `%s' truncated",filename); hash= userdb_hash(userid); i= hash % n; if (fseek(file, i*sizeof(struct userentry), SEEK_SET)) ohshite("User database `%s' unseekable",filename); *file_r= file; *initial_r= i; *n_r= n; }
int main(void){ int total = 0; init_table(); for(int i = 0; i < 3; i++){ lock_t *l = (lock_t *) surely_malloc(sizeof(lock_t)); thread_locks[i] = l; results[i] = (int *) surely_malloc (sizeof(int)); makelock((void *)l); } for(int i = 0; i < 3; i++){ int *t = (int *) surely_malloc(sizeof(int)); *t = i; spawn((void *)&f, (void *)t); } for(int i = 0; i < 3; i++){ lock_t *l = thread_locks[i]; acquire(l); freelock2(l); free(l); int *r = results[i]; int i = *r; free(r); total += i; } //total should be equal to 3 }