Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "graphic.h"
- #include <pthread.h>
- #include <sys/sysinfo.h>
- //get_nprocs_conf
- //Remplir le tableau de la structure ppointex
- //Tableau de taille 25 dans tableau 8 -> tableau 1 = thread/core 1
- #define N 200
- typedef struct {
- int x,y,color;
- } Point;
- typedef struct{
- Point *pointsProc[];
- pthread_mutex_t mutex;
- }Ppointex;
- void *my_thread_process (void * arg) {
- /*Ppointex *pex = (Ppointex*) arg;
- while(getppid()!=1){
- if(pthread_mutex_lock(&pex->mutex) != 0){
- perror("pthread_mutex_lock");
- exit(1);
- }
- (pex->pp)->x+=g_random()%2?1:-1;
- (pex->pp)->y+=g_random()%2?1:-1;
- if(pthread_mutex_unlock(&pex->mutex) != 0){
- perror("pthread_mutex_unlock");
- exit(1);
- }
- sleep(0.02);
- }
- pthread_exit (NULL);*/
- }
- int main() {
- Point points[N];
- int i,caseTableau;
- pthread_t th;
- void * ret;
- int nbProc= get_nprocs_conf();
- caseTableau=N/nbProc;
- Ppointex ppointex;
- ppointex.pointsProc=(Point*)sizeof(caseTableau*sizeof(Point));
- for(i=0; i<N; ++i) {
- points[i].x=g_random()%(G_WIDTH-200)+100;
- points[i].y=g_random()%(G_HEIGHT-200)+100;
- points[i].color=g_random()%G_NB_COLORS;
- }
- for(i=0; i<N; ++i) {
- pthread_mutex_init(&p[i].mutex,NULL);
- p[i].pp=&points[i];
- if(pthread_create (&th,NULL,my_thread_process,&p[i]) < 0){
- fprintf (stderr,"pthread_create error for thread \n");
- exit (1);
- }
- }
- g_init();
- while(1){
- g_clear();
- for(i=0; i<N; ++i){
- g_draw(points[i].x, points[i].y, points[i].color);
- }
- g_flush();
- g_msleep(20);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement