作業系統›Ch6 行程同步(Process Synchronization)
第 9 題/共 32 題
◀ OS 9/32
9. pthread、Race Condition
#OS-06-009易pthreadRace Condition

Consider the following C code for creating two threads. Which statement(s) are correct?

// header files here
int count = 0;

void *mythread(void *arg) {
  for (int i=0; i<10000; i++) {
    // wait for some time
    count += 1;
  }
  return(NULL);
}

int main() {
  pthread_t p1, p2;
  pthread_create(&p1, NULL, mythread, NULL);
  pthread_create(&p2, NULL, mythread, NULL);
  pthread_join(p2, NULL); pthread_join(p1, NULL);
  printf("%d", count);
  return 0;
}
📄 交大112
跳轉到第題
▤完整推導請見《WH 資工筆記 · 作業系統》Ch6 行程同步(Process Synchronization)
本章題號 · 1–20 / 32