Skip to content

get_order lock의 위치 관련 문의 #12

@lukeqwaszx

Description

@lukeqwaszx

안녕하세요,

  if (server_ctx.list.head == NULL) return NULL;

  pthread_mutex_lock(&server_ctx.lock);

  target_node = server_ctx.list.head;

  if (server_ctx.list.head == server_ctx.list.tail) {
    server_ctx.list.head = NULL;
    server_ctx.list.tail = NULL;
  } else {
    server_ctx.list.head = server_ctx.list.head->next;
  }

  server_ctx.list.count--;

  pthread_mutex_unlock(&server_ctx.lock);

mcdonalds.c의 get_order()가 이렇게 구현되어 있는 상황인데, 이런 구현 하에서 list의 node가 하나 있고 thread가 두 개 있을 때,thread 1에서 list.head == NULL이 아님을 확인하고 context switch가 이루어져 thread 2에서 get_order()가 이루어지고 다시 thread1으로 context switch되는 경우 list.count가 -1이 되는 문제가 존재하는 것 같아 issue드립니다!

Metadata

Metadata

Assignees

No one assigned

    Labels

    solvedQuestion solved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions