Operating system 操作系统线程和锁定问题

Operating system 操作系统线程和锁定问题,operating-system,Operating System,我不知道为什么会有一些失落。如何更新代码,使多个检索和插入操作可以并行运行? 非常感谢。 当我运行.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 * retriev

我不知道为什么会有一些失落。如何更新代码,使多个检索和插入操作可以并行运行? 非常感谢。 当我运行.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;
}

首先尝试最简单、最可靠的解决方案-互斥循环插入/检索。您能分享整个代码吗