I created the following multi-threaded program in linux:
Code:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
//using namespace std;
void *thread_funk(void *start);
void *thread_funk(void *start)
{
int *value1 = (int *)start;
//while(*value1 < 4)
while(1) {
if (*value1 == 3)
{
printf("Cifra je %d\n", *value1);
pthread_exit(NULL);
}
}
}
int main(int argc, char *argv[])
{
pthread_t thread1;
int *value = (int *)malloc(sizeof(int));
*value = 0;
// Create new thread.
pthread_create(&thread1, NULL, (void *)&thread_funk, (void *)value);
while(*value < 5)
{
//sleep(5);
*value++;
}
free(value);
exit(0);
}
It compiles perfectly bit it would not work! Why?
Please help.