不知道为什么有些丢了。如何更新代码以便多个检索和插入操作可以并行运行?谢谢你。当我运行我的 .c 文件时,它显示:
$ ./parallel_hashtable 8
[main] Inserted 100000 keys in 0.002476 seconds
[thread 7] 4304 keys lost!
.....
[main] Retrieved 65634/100000 keys in 0.792488 seconds
我的代码:
bucket_entry * retrieve(int key) {
bucket_entry *b;
for (b = table[key % NUM_BUCKETS]; b != NULL; b = b->next) {
if (b->key == key) return b;
}
return NULL;
}
void insert(int key, int val) {
int i = key % NUM_BUCKETS;
bucket_entry *e = (bucket_entry *) malloc(sizeof(bucket_entry));
if (!e) panic("No memory to allocate bucket!");
e->next = table[i];
e->key = key;
e->val = val;
table[i] = e;
}