Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <pthread.h>
- #include <string.h>
- #include <sys/file.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <time.h>
- void *fun_watek1(void * p);
- void *fun_watek2(void * p);
- struct liczby{
- int x;
- int y;
- };
- int retval;
- struct liczby message;
- int main() {
- message.x = 4;
- message.y = 2;
- pthread_t watek1;
- pthread_t watek2;
- pthread_create(&watek1, NULL, fun_watek1, (void *)&message);
- pthread_create(&watek2, NULL, fun_watek2, (void *)&message);
- pthread_join(watek1, NULL);
- printf("%d + %d = %d\n",message.x, message.y, retval);
- pthread_join(watek2, NULL);
- printf("%d - %d = %d\n",message.x, message.y, retval);
- return0;
- }
- void *fun_watek1(void * p) {
- printf("Watek 1: %lu, PID: %d\n", pthread_self(), getpid());
- struct liczby * l = (struct liczby*) p;
- retval = l->x+l->y;
- return0;
- }
- void *fun_watek2(void * p) {
- printf("Watek 2: %lu, PID: %d\n", pthread_self(), getpid());
- struct liczby * l = (struct liczby*) p;
- retval = l->x-l->y;
- return0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement