Posts

Showing posts from 2011

Mutual Exclusion among 2 different classes

Hello There!, Recently I came across a very interesting problem, and the problem statement is as follows There are 2 classes called A and B, with the methods - methodA() and methodB(). The class definition vaguely looks like this. class A {   public methodA() {       statementA;   } } class B {     public methodB() {          statementB;    } } Now the 2 classes's methods contain a set of statements represented by statementA and statementB . Our goal here is to make these 2 statements in 2 different class, execute in a mutually exclusive manner. That means, when any thread executes statementA, none of the threads must be allowed to execute statementB. And when any thread executes statementB, none of the threads must be allowed to execcute statementA. Meanwhile, unlimited threads can simultaneously access statementA alone or statementB alone. methodA and methodB can be changed in any form (making them synchronized or whatever). But method signatures are not