+ Reply to Thread
Results 1 to 2 of 2

Thread: Extend Lock class

  1. #1
    Surfer is offline Senior Member
    Join Date
    Mar 2010
    Posts
    321

    Extend Lock class

    You have a Lock which has lock and unlock procedure

    Code:
    class Lock{
    	public:
    		Lock();
    		UnLock()
    };
    Lock function locks any resources, it does not check whether it has been already locked by same thread.
    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.

  2. #2
    puspendra Guest
    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;
    }

    };

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts