#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include <time.h>
#include <stdlib.h>

struct coupe {int* tableau; int debut; int fin;int* res;};

typedef struct coupe arg_thread;

void* mythread(void* arg){
    arg_thread* asommer = (arg_thread*)arg;
    asommer->res = malloc(sizeof(int));
    *(asommer->res)=0;
    for (int i= asommer->debut;i<=asommer->fin;i++){
        *(asommer->res) +=asommer->tableau[i];
    }
    return NULL;

}

int main(){

pthread_t t1;
pthread_t t2;
int* tableau = malloc(1000*sizeof(int));
for (int i=0;i<1000;i++){
    tableau[i]=i+1;
}

int* res1;
int* res2;

arg_thread a1 ={tableau, 0,500,res1};
arg_thread a2 ={tableau,501,999,res2};


pthread_create(&t1,NULL,mythread,&a1);
pthread_create(&t2,NULL,mythread,&a2);
pthread_join(t1,NULL);
pthread_join(t2,NULL);
printf("%d", *(a1.res) + *(a2.res));
}