Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » MT/Locking Questions
MT/Locking Questions [message #15529] Mon, 28 April 2008 15:23 Go to previous message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
This is a general question about using Mutex locking. Does locking occur on a per object basis? what about static variables?

Also, how do locks work in class hierarchies?
For example:
class Parent{
  Mutex  lock;
  String mydata;
  virtual void DoSomething(){
     for(int i=0;i<10;++i){
       Cout() << mydata << "\n;"
     }
  };
};

class Child1{
  void DoSomething(){
    INTERLOCKED_(lock){
       mydata = "Foo";
       Parent::DoSomething();
    }
  }
};

class Child2{
 void DoSomething(){
    INTERLOCKED_(lock){
       mydata = "Bar";
       Parent::DoSomething();
    }
  }
};

CONSOLE_APP_MAIN{
  Parent * c1 = new Child1();
  Parent * c2 = new Child2();
  
  Thread().Run(callback(&c1, &Parent::DoSomething);
  Thread().Run(callback(&c2, &Parent::DoSomething);

  delete c1;
  delete c2;
}

Since 2 separate instances of the object are created, both DoSomething()'s can run concurrently, correct?
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to send broadcast
Next Topic: PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP not defined
Goto Forum:
  


Current Time: Sun Sep 22 21:09:26 CEST 2019

Total time taken to generate the page: 0.00907 seconds