septembre + octobre
This commit is contained in:
BIN
SCR/TP06/ex1
Executable file
BIN
SCR/TP06/ex1
Executable file
Binary file not shown.
30
SCR/TP06/ex1.c
Normal file
30
SCR/TP06/ex1.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define NUM_THREADS 16
|
||||
|
||||
void *thread(void *thread_id) {
|
||||
int id = *((int *) thread_id);
|
||||
printf("Hello from thread %d\n", id);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main() {
|
||||
pthread_t threads[NUM_THREADS];
|
||||
int tabid[NUM_THREADS];
|
||||
for (int i = 0; i < NUM_THREADS; i++){
|
||||
tabid[i] = i+1;
|
||||
}
|
||||
for (int i = 0; i < NUM_THREADS; i++){
|
||||
assert( pthread_create(&threads[i], NULL, thread, &tabid[i]) == 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUM_THREADS; i++){
|
||||
assert( pthread_join(threads[i], NULL) == 0);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
65
SCR/TP06/ex2.c
Normal file
65
SCR/TP06/ex2.c
Normal file
@@ -0,0 +1,65 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user