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


extern int pthread_join(pthread_t thread, void **value_ptr);
extern int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *);

int thread_func(int *stop_condition)
{
    int c=0;
    while(*stop_condition)
    {
        c++;
        printf("thread count %d\n",c);
        sleep(1);
    }
    return c;
}

int main()
{
    pthread_t thread;
    int thread_return = 0;
    int stop_condition = 1;

    pthread_create(&thread, NULL, (void*(*)(void*)) thread_func, &stop_condition);

    int c = 0;
    while(c < 5)
    {
        c++;
        printf("main thread count %d\n",c);
        sleep(3);
    }

    stop_condition = 0;

    pthread_join(thread, (void**)&thread_return);
    printf("thread joined with value %d\n", thread_return);

    return EXIT_SUCCESS;
}
