설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main-race.c 464B

1234567891011121314151617181920212223
  1. #include <stdio.h>
  2. #include "mythreads.h"
  3. int balance = 0;
  4. pthread_mutex_t mut;
  5. void* worker(void* arg) {
  6. pthread_mutex_lock(&mut);
  7. balance++; // protected access
  8. pthread_mutex_unlock(&mut);
  9. return NULL;
  10. }
  11. int main(int argc, char *argv[]) {
  12. pthread_t p;
  13. Pthread_create(&p, NULL, worker, NULL);
  14. pthread_mutex_lock(&mut);
  15. balance++; // unprotected access
  16. pthread_mutex_unlock(&mut);
  17. Pthread_join(p, NULL);
  18. return 0;
  19. }