[Next] 
[Up] 
[Previous]   
 Next: Object Groups
 Up: Remote Method Invocation
 Previous: Remote Method Invocation
 
 TACO provides  both Mutex and Lock
classes to achieve a similar semantic 
to Java's synchronized methods. 
The Lock class provides a locking mechanism
for blocks based on a constructor, that enters a critical section
and a destructor that releases the section.
Now we can easily modify
the Sheep class for use in concurrent environments.
#include "taco/sync/Mutex.h"
#include "taco/sync/Lock.h"
class Sheep: public Mutex {
 public:
    int feed(int food) 
    {
        Lock guard(this);
        my_weight += food;
        return my_weight;
    }
    ...
};
When we declare an instance of Lock at the beginning
of a block, we can ensure correct locking even when exceptions occur.