xv6-lab/answers-thread.txt
2023-02-01 14:53:46 +00:00

13 lines
560 B
Plaintext

Q: Why are there missing keys with 2 threads, but not with 1 thread? Identify a sequence of events with 2 threads that can lead to a key being missing.
A: Suppose K1 % NBUCKET === K2 % NBUCKET = i0
T1 put(K1);
T2 put(K2);
T1 not found
T2 not found
T1 insert(K1, V1, &table[i0], table[i0])
T2 insert(K2, V2, &table[i0], table[i0])
T1 malloc e1, e1->key = K1, e1->value = V1, e1->next = table[i0]
T2 malloc e2, e2->key = K2, e2->value = V2, e2->next = table[i0]
T1 *(&table[i0]) = e1
T2 *(&table[i0]) = e2 <---- K1 lost