Parallel Processing

CPU1 CPU2 CPU3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
 
void* f1(void* arg){
    int whos_better;
    whos_better = 1;
    while(1)
        printf("Thread 1: thread %d is better.\n", whos_better);
 
        return NULL;
}
 
void* f2(void* arg){
    int whos_better;
    whos_better = 2;
    while(1)
        printf("Thread 2: thread %d is better.\n", whos_better);
 
    return NULL;
}
 
int main(int argc, char **argv){
    pthread_t th1, th2;
 
    pthread_create(&th1, NULL, f1, NULL);  
    pthread_create(&th2, NULL, f2, NULL);
 
    pthread_join(th1, NULL);
    pthread_join(th2, NULL);
 
    pthread_exit(NULL);
}