Iam trying to understand and find solution to one of my problem .
Let me explain my logic and the blocking aspect in that.
There are two threads
Thread1 and Thread2 these two operate on globa buffer.
Thread1 generates global list gl , thread 2 uses it by copying it into its own local copy .
The global buffer is secured by mutex lock.
Here thread2 is in infinite loop like below
the thread2 would be waken up by thread1 by unlocking the mutex lock1.Code:while(1) { pthread_mutex(&lock1); pthread_mutex_lock(&lock2); global list copy to local list. pthread_mutex_unlock(&lock2); for(i=0;i<number of nodes in the list;i++) { process the local list } }
like below
The blocking issue for me here is ,Code:thread1 { pthread_mutex_lock(&lock2); prepare global list gl pthread_mutex_unlock(&lock2) ptherad_mutex_unlock(&lock1) }
lets take a case where thread2 is in processing the list ,
in the mean time if thread1 provides new global list ,
How will thread 2 behave,i am afraid that this will corrupt the local list ( as this is not secured by lock ) and also there is no mechanism to tell the thread 2 from thread 1 that to consider the new list .
How can i over come this problem .
You help would be highly appreciated.



4Likes
LinkBack URL
About LinkBacks



