What can I do when Mutex don't stop all threads?

I’ve just experiment an issue regarding Mutex cpp class. Seems if there’s more than two thread try to use Mutexed resource sometimes protected code can be executed same time. It’s possible that is due to use of different instances of same class cointains Mutex usage?

I mean, it’s possible for the following code execute code protected by Mutex more than one at same time?


class SomeOps {
   var _mutex:Mutex;
   public new() {
       _mutex = new Mutex();
   }

   public function opUsingMutex() {
       _mutex.acquire();
      makeOperation();
      _mutex.release();
   }
}

class UsingSomeOps {
    public function operation() {
        var someOps:SomeOps = new SomeOps();
        someOps.opUsingMutex();
    }
}

class Main {
    public new() {
        var w1:BackgroundWorker = new BackgroudWorker();
        w1.doWork.add(
           function(data) {
                new UsingSomeOps().operation();
           }
        );
        w1.run();
        var w2:BackgroundWorker = new BackgroudWorker();
        w2.doWork.add(
           function(data) {
                new UsingSomeOps().operation();
           }
        );
        w2.run();
        var w3:BackgroundWorker = new BackgroudWorker();
        w3.doWork.add(
           function(data) {
                new UsingSomeOps().operation();
           }
        );
        w3.run();
    }
}

Thanks a lot in advance.
David.

I’ve made some others investigations and discovered that using same Mutex shared via a singleton class all threads are interceped and regular stopped. Is this the desiderated behavior or can be considered a bug?

David.

I think normally you would share one mutex across multiple threads that access the same resources. If each background thread has it’s own mutex, I’m not sure that will work as intended?