Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<pthread.h>
- #include<stdlib.h>
- #include<unistd.h>
- typedef struct s {
- int a;
- int b;
- int sum;
- } s;
- void* sum(void* inp) {
- s* inputs = (s*)inp;
- int a = inputs -> a;
- int b = inputs -> b;
- inputs -> sum = a+b;
- sleep(3);
- return NULL;
- }
- int main() {
- pthread_t tid;
- s* operands = (s*)malloc(sizeof(s));
- operands->a = 1;
- operands->b = 1;
- pthread_create(&tid, NULL, sum, (void*)(operands));
- pthread_join(tid, NULL);
- printf("%d\n", operands->sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement