BUT2/SCR/TP06/ex2.c

66 lines
1.4 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <assert.h>
typedef struct duel{
int participant1;
int participant2;
} duel;
void *tournois(void *thread_id) {
int id = *((int *) thread_id);
printf("Hello from thread %d\n", id);
return NULL;
}
int puissance2(int n){
for (int p=1; p<n; p*=2){}
if (p==n){
return 1;
}
return 0;
}
duel* Formercouple(participant*, nbParticipant){
int i;
int c;
duel couple[nbParticipant/2];
for (i=0; i<nbParticipant; i++){
if (participant[])
}
}
int main(int argc, char** argv[]) {
int participant[argc];
int nbDuel = argc/2;
int nbParticipant = argc;
pthread_t threads[nbDuel];
assert(puissance2(argc)==1);
for (int i = 0; i < argc; i++){
participant->nom = argv[i];
participant->id = i;
}
while (nbDuel > 1){
for (int i = 0; i < nbDuel; i++){
duel[nbDuel] tabDuel;
participant participant2;
for (int x=0, y=0, )
participant duel[] = {participant[i], participant[i+1]};
assert( pthread_create(&threads[i], NULL, tournois, &participant[i]) == 0);
}
for (int i = 0; i < NUM_THREADS; i++){
assert( pthread_join(threads[i], NULL) == 0);
}
nbParticipant /= 2;
nbDuel /= 2;
}
return EXIT_SUCCESS;
}