You have a Lock which has lock and unlock procedure
Lock function locks any resources, it does not check whether it has been already locked by same thread.Code:class Lock{ public: Lock(); UnLock() };
UnLock function unlocks any resources if it Locked, it does not check how many times that resource has been locked.
You need to extend this class and implement Lock and UnLock function in such a way that if any thread locks any resource n times, UnLock should be called n times to completely unlock that.
class counter{
public:
int counter;
int thread_id;
}
class myLock extend Lock{
private:
counter count;
public:
myLock(id){
count.id=id;
count.counter++;
if(count.counter == 0)
Lock();
}
myUnLock()
{
if(count.counter>0)
count.counter--;
if(count.counter == 0)
Unlock();
else
count.counter = -1;
}
};
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks