Project

General

Profile

Bug #1201 » ust_fd_mutex_battle.c

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

 
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <pthread.h>

void* do_victim(void* arg) {
close(0xab);
return NULL;
}

void *do_killer(void *arg) {
pthread_t victim = *((pthread_t *) arg);
pthread_cancel(victim);
close(0xac);
}

int main() {
int i;
int round = 1;
pthread_t killer;
pthread_t victim;

while(1) {
printf("--------------------[ %d ]---------------------------\n", round);
printf("Creating workers\n");
pthread_create(&victim, NULL, do_victim, NULL);
pthread_create(&killer, NULL, do_killer, &victim);
printf("Waiting for workers to join\n");
pthread_join(victim, NULL);
printf("Victim joined\n");
pthread_join(killer, NULL);
printf("killer joined\n");
round += 1;
printf("-----------------------------------------------------\n");
}
}
(1-1/2)