Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <pthread.h>
- #include <time.h>
- #include <stdlib.h>
- struct task_t {
- char* data;
- int start;
- int end;
- };
- void* fun(void* arg) {
- struct task_t* task = (struct task_t*)arg;
- for(int i = task->start; i <= task->end; i++){
- if(strncmp((task->data+i),"ABCACD",6) == 0)
- printf("%d\n",i);
- }
- }
- int main(int argc, char **argv){
- srand(time(NULL));
- printf("Hello\n");
- char tab[1000000] = {"0"};
- int x = 0;
- for(int i = 0; i < 1000000; i ++){
- x = rand()%4;
- switch(x){
- case 0: tab[i] = 'A';
- break;
- case 1: tab[i] = 'B';
- break;
- case 2: tab[i] = 'C';
- break;
- case 3: tab[i] = 'D';
- break;
- default: return 6;
- }
- }
- struct task_t task1 = {tab, 0, 250000};
- struct task_t task2 = {tab, 249995, 500000};
- struct task_t task3 = {tab, 499995, 750000};
- struct task_t task4 = {tab, 749995, 999999};
- pthread_t th1, th2, th3, th4;
- pthread_create(&th1, NULL, fun, &task1);
- pthread_create(&th2, NULL, fun, &task2);
- pthread_create(&th3, NULL, fun, &task3);
- pthread_create(&th4, NULL, fun, &task4);
- pthread_join(th1, NULL);
- pthread_join(th2, NULL);
- pthread_join(th3, NULL);
- pthread_join(th4, NULL);
- printf("bye\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement