very basic but nonunderstandable
after executing the code below I expect to get on the output:
9
9
but instead I get:
4
9
#include <stdio.h>
#include <pthread.h>
int a;
pthread_t thread_id;
pthread_mutex_t mutex1=PTHREAD_MUTEX_INITIALIZER;
void *thread_function(void *unused)
{
pthread_mutex_lock(&mutex1);
a=9;
sleep(3);
printf("%i\n",a);
pthread_mutex_unlock(&mutex1);
return NULL;
}
int main()
{
pthread_create(&thread_id,NULL,&thread_function,NULL);
a=4;
printf("%i\n",a);
pthread_join(thread_id,NULL);
return 0;
}

