Hi your code is not correct which is define below:
pthread_create(&thread_id, NULL, myThreadFun1, NULL);
pthread_mutex_t lock;
void *myThreadFun1(void *vargp)
{
pthread_mutex_lock(&lock);
int i=0;
for(i=0;i<200;i++)
printf ("i=%d",i);
pthread_mutex_unlock(&lock);
}
void *myThreadFun2(void *vargp){
int j=0;
for(j=0; j<200; j++)
printf("j=%d", j);
}
int main()
{
pthread_t thread_id;
printf("Before Thread\n");
if(pthread_mutex_init(&lock, NULL) !=0){
printf("Mutex failed");
return -1;
}
pthread_create(&thread_id, NULL, myThreadFun1, NULL);
pthread_create(&thread_id, NULL, myThreadFun2, NULL);
pthread_join(thread_id, NULL);
printf("After Thread\n");
pthread_join(thread_id, NULL);
pthread_join(thread_id,NULL);
pthread_mutex_destroy(&lock);
}
[/code]
for more click this link:-
https://www.cetpainfotech.com/