kaist-cp/cs431

[Question] Failing test cache_no_reader_block

Closed this issue · 3 comments

For the cache implementation, I am failing that last test case:
image

For my implementation of the cache I am using the following structure:
image

My theory is as follows:
When we write a value, we:

  1. wait to get a write lock on the cache
  2. wait to get a write lock on the value at key (k)
  3. after we acquire the inner lock, we drop the outer lock to allow others to read all values, EXCEPT for the value we are currently writing at key (k)

To do this, we create a temp value at the key, and when other readers notice there is a temp value, they will attempt to acquire a read lock on key (k) rather than a write lock, and they will be blocked until the original thread has finished writing to value at key (k)

  1. When we are done, we drop the inner lock

I am having trouble understanding what the test case is specifically testing - the rust code is a bit complicated for me
image

Hello. The code is testing following:

  1. T1 is inserting 1
  2. While inserting its closure spawns two threads T2 and T3, and since T2 is also inserting 1, its closure shouldn't be run (note the panic! there.
  3. T3 is inserting a different key, so it shouldn't be blocked by T1 or T2.
  4. T1 is blocked until T3 has inserted a value into HashMap (note the use of channels).

I suggest you to double check when you're acquiring/dropping the locks, and make sure two threads reading/writing different keys doesn't block each other.

How is this test case different from cache_no_block_disjoint? isn't that also testing that two threads writing different keys will block each other?

This test has two threads trying to read from key 1. The no_block_disjoint only tests threads reading from different keys.