Project

General

Profile

Bug #1201 » ust_fd_mutex_battle.c

Tai Dinh, 10/04/2019 09:44 AM

 
1
#include <unistd.h>
2
#include <sys/types.h>
3
#include <sys/wait.h>
4
#include <sys/prctl.h>
5
#include <stdio.h>
6
#include <string.h>
7
#include <stdlib.h>
8
#include <fcntl.h>
9
#include <errno.h>
10
#include <pthread.h>
11

    
12
void* do_victim(void* arg) {
13
  close(0xab);
14
  return NULL;
15
}
16

    
17
void *do_killer(void *arg) {
18
  pthread_t victim = *((pthread_t *) arg);
19
  pthread_cancel(victim);
20
  close(0xac);
21
}
22

    
23
int main() {
24
  int i;
25
  int round = 1;
26
  pthread_t killer;
27
  pthread_t victim;
28

    
29
  while(1) {
30
    printf("--------------------[ %d ]---------------------------\n", round);
31
    printf("Creating workers\n");
32
    pthread_create(&victim, NULL, do_victim, NULL);
33
    pthread_create(&killer, NULL, do_killer, &victim);
34
    printf("Waiting for workers to join\n");
35
    pthread_join(victim, NULL);
36
    printf("Victim joined\n");
37
    pthread_join(killer, NULL);
38
    printf("killer joined\n");
39
    round += 1;
40
    printf("-----------------------------------------------------\n");
41
  }
42
}
(1-1/2)