Resolve php "deadlock"

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-05-22T11:09:34Z Indexed on 2010/05/22 11:10 UTC
Read the original article Hit count: 301

Filed under:
|
|

Hey all,

I'm currently running into a situation that I guess would be called deadlock.

I'm implementing a message service that calls various object methods.. it's quite similar to observer pattern..

Here's whats going on:

Dispatcher.php

Dispatcher.php

<?
class Dispatcher {
...
    public function message($name, $method) {

    // Find the object based on the name
    $object = $this->findObjectByName($name);

    // Slight psuedocode.. for ease of example
    if($this->not_initialized($object))
        $object = new $object(); // This is where it locks up.
    }

    return $object->$method();
...
}

class A {
    function __construct()
    {
        $Dispatcher->message("B", "getName");
    }

    public function getName() {
        return "Class A";
    }

}

class B {
    function __construct()
    {
            // Assume $Dispatcher is the classes
        $Dispatcher->message("A", "getName");
    }

    public function getName() {
        return "Class B";
    }

}

?>

It locks up when neither object is initialized. It just goes back and forth from message each other and no one can be initialized.

Any help would be immensely helpful..

Thanks! Matt Mueller

© Stack Overflow or respective owner

Related posts about php

Related posts about deadlock