Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Stwórz dwa wątki w programie. Każdemu z nich przekaż przez parametr funkcji dwie liczby. Pierw-
- szy wątek niech policzy sumę tych liczb, drugi różnicę. Obie wartości należy wypisać na ekran
- w wątkach.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- struct number {
- int x, y;
- };
- void *add_thread_function(void *arg)
- {
- struct number *num = arg;
- printf("Dodawanie: %d\n", num->x+num->y);
- return EXIT_SUCCESS;
- }
- void *subtract_thread_function(void *arg)
- {
- struct number *num = arg;
- printf("Odejmowanie: %d\n", num->x-num->y);
- return EXIT_SUCCESS;
- }
- int main(void)
- {
- pthread_t add_thread, subtract_thread;
- struct number *num;
- num->x = 5;
- num->y = 3;
- pthread_create(&add_thread, NULL, add_thread_function, (void *)num);
- pthread_create(&subtract_thread, NULL, subtract_thread_function, (void *)num);
- pthread_join(add_thread, NULL);
- pthread_join(subtract_thread, NULL);
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment