1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define Sun 5 10 #define DEF 1024*1024 11 typedef struct Date 12 { 13 14 char* r_begin; 15 char* w_begin; 16 int size; 17 }data; 18 int fid,mid,rid; 19 int count; 20 long long num; 21 char *witeid; 22 char *readid; 23 pthread_mutex_t mutex; 24 void sys_error(char* str) 25 { 26 perror(str); 27 exit(1); 28 } 29 void *mycapy(void * arg) 30 { 31 char* buf= (char*)malloc(sizeof(char)); 32 int n; 33 int i =0; 34 struct Date *dt = (struct Date*)arg; 35 char* readf = dt->r_begin; 36 char* writef = dt->w_begin; 37 for(i;i size;i++) 38 { 39 strncpy(buf,readf,1); 40 *writef=*buf; 41 pthread_mutex_lock(&mutex); 42 count++; 43 pthread_mutex_unlock(&mutex); 44 readf++; 45 writef++; 46 47 48 } 49 free(dt); 50 free(buf); 51 return(void*)0; 52 } 53 54 void Mypthreadcreate(int sum,int yu,int sleek) 55 { 56 int i; 57 pthread_t *pid =(pthread_t*) malloc(sizeof(pthread_t)*sum); 58 // pthread_t pid ; 59 for(i=0;i size = sleek+yu; 64 else 65 da->size = sleek; 66 da->r_begin = readid + i*sleek; 67 da->w_begin = witeid + i*sleek; 68 int clt =pthread_create(&pid[i],NULL,mycapy,(void*)da); 69 // int clt =pthread_create(&pid,NULL,mycapy,(void*)da); 70 if(clt!=0) 71 { 72 printf("pthread_cread error %s\n",strerror(clt)); 73 } 74 } 75 int k; 76 for(k=0;k DEF)166 {167 int NUM = DEF;168 int yuy = num%NUM;169 int n = num/NUM;170 int ii =0;171 printf("n = %d\n",n);172 if(argv==4)173 { int mm =atoi(argc[3]);174 yu = NUM%mm;175 sleek = NUM/mm;176 sum = mm;177 }178 else179 {180 sleek = NUM/Sun;181 sum = Sun;182 yu = NUM%Sun;183 }184 Mymmap(sum,sleek,n,yuy,yu);185 }186 187 188 189 close(fid);190 191 sleep(2);192 return 0;193 }194 195