I am trying pthread example. Here is my code:
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
void*AsalK1(void *gelen);
int main(){
int *i;
i= new int;
*i=1;
int sonSayi;
pthread_t th1, th2, th3, th4;
printf("---------------------------------------------\n");
printf("| Threadler ile Asal Sayi Bulma |\n");
printf("---------------------------------------------\n");
printf("Son sayi degeri: 1000000 \n");
int r1=pthread_create( &th1, NULL, AsalK1, (void *)i);
*i=3;
int r2=pthread_create( &th2, NULL, AsalK1, (void *)i);
*i=5;
int r3=pthread_create( &th3, NULL, AsalK1, (void *)i);
*i=7;
int r4=pthread_create( &th4, NULL, AsalK1, (void *)i);
pthread_join( th1, NULL);
pthread_join( th2, NULL);
pthread_join( th3, NULL);
pthread_join( th4, NULL);
return 0;
}
void *AsalK1(void *gelen){
int bas= *gelen;
printf("bas :&d\n",bas);
}
and i use this code to compile :
gcc -lpthread ThreadDeneme.cpp
or
g++ -lpthread ThreadDeneme.cpp
And the Error Says:
cannot initialize a variable of type 'int' with an lvalue of type 'void' int bas= *gelen;
I use this:
int bas= (int *) gelen;
but error still in progress.
I read: