Hi All,
Suppose that my program is such that
int counter;
pthread_mutex_t mutex1 = PTHREAD_MUTEX_I NITIALIZER;
void *functionC()
{
pthread_mutex_l ock( &mutex1 );
counter++;
printf("Counter value: %d\n",counter);
pthread_mutex_u nlock( &mutex1 );
}
int main()
{
pthread_t thread_id;
pthread_create (&thread_id, NULL, &functionC, NULL);
//increment counter in main also
}
Will there be a problem when I do this?If the thread is schduled first
will the main() wait untill the thread unlocks?
If not,Is there anyway to lock the variable in the main program as
well as in the thread.
Cheers
Suppose that my program is such that
int counter;
pthread_mutex_t mutex1 = PTHREAD_MUTEX_I NITIALIZER;
void *functionC()
{
pthread_mutex_l ock( &mutex1 );
counter++;
printf("Counter value: %d\n",counter);
pthread_mutex_u nlock( &mutex1 );
}
int main()
{
pthread_t thread_id;
pthread_create (&thread_id, NULL, &functionC, NULL);
//increment counter in main also
}
Will there be a problem when I do this?If the thread is schduled first
will the main() wait untill the thread unlocks?
If not,Is there anyway to lock the variable in the main program as
well as in the thread.
Cheers
Comment