Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <pthread.h>
- #include <unistd.h>
- static void * sum_line(int nr_line);
- int Sum;
- int A[4][4];
- int main() {
- pthread_t tid;
- Sum=0;
- printf("\nOrig thread tid(%d) Sum=%d", pthread_self(), Sum);
- pthread_create(&tid, NULL, &sum_line(0), NULL);
- printf("\nChild thread was created tid(%d)", tid);
- pthread_join(tid,NULL);
- printf("\nOrig thread tid(%d)-->Child thread ended tid(%d) Sum=%d",pthread_self(), tid, Sum);
- printf("\n");
- }
- static void * sum_line(int nr_line) {
- int i;
- for(i=0;i<4;i++) {
- Sum=Sum+A[i];
- printf("\nChild thread tid(%d), i=%d, Sum=%d",pthread_self(),i,Sum);
- sleep(2);
- }
- printf("\nChild thread tid(%d)--> ending", pthread_self());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement