#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *print_and_increment(void *arg) {
    int num = *((int *)arg);
    printf("Wartosc: %d\n", num);
    num++;
    int *result = malloc(sizeof(int));
    *result = num;
    pthread_exit(result);
}

int main() {
    pthread_t thread1, thread2;
    int num1 = 5, num2 = 10;
    int *res1, *res2;

    pthread_create(&thread1, NULL, print_and_increment, &num1);
    pthread_create(&thread2, NULL, print_and_increment, &num2);

    pthread_join(thread1, (void **)&res1);
    pthread_join(thread2, (void **)&res2);

    printf("Watek 1 zwrocil: %d\n", *res1);
    printf("Watek 2 zwrocil: %d\n", *res2);

    free(res1);
    free(res2);

    return 0;
}
