Skip to content

an issue about sema of Segment #4

@erician

Description

@erician

In my opinion, you want to implement rwlock with sema, which is a data member of Segment, but there is something wrong with it. Consider this situation: the first thread (T1) goes to C1(showed in bellow codes) and sleeps, and the second thread(T2) splits the same segment with INPLACE mode and changes the pattern. When T1 wakes up, it inserts the key-value into that segment, but, this key-value may not belong to that segment since the pattern may be not right, and it will be treated as invalid record and removed, which is an issue.

int Segment::Insert(Key_t& key, Value_t value, size_t loc, size_t key_hash) {
#ifdef INPLACE
  if (sema == -1) return 2;
  if ((key_hash >> (8*sizeof(key_hash)-local_depth)) != pattern) return 2;
  auto lock = sema;                                       #C1
  int ret = 1;
  while (!CAS(&sema, &lock, lock+1)) {
    lock = sema;
  }
.....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions