Exemple #1
0
    void run() override
    {
        setName( "Slave" );
        co::ConnectionDescriptionPtr desc = new co::ConnectionDescription;
        co::LocalNodePtr node = new co::LocalNode;
        node->addConnectionDescription( desc );
        TEST( node->listen( ));

        co::NodePtr server = new co::Node;
        co::ConnectionDescriptionPtr serverDesc =
            new co::ConnectionDescription;

        _port.waitNE( 0 );
        serverDesc->port = _port.get();
        server->addConnectionDescription( serverDesc );

        _barrier.waitNE( 0 );
        TEST( node->connect( server ));

        co::Barrier barrier( node, co::ObjectVersion( _barrier.get( )));
        TEST( barrier.isGood( ));
        TEST( barrier.getVersion() == co::VERSION_FIRST );

        std::cerr << "Slave enter" << std::endl;
        TEST( barrier.enter( ));
        std::cerr << "Slave left" << std::endl;

        barrier.sync( co::VERSION_FIRST + 1 );
        TEST( barrier.getVersion() == co::VERSION_FIRST + 1 );

        std::cerr << "Slave enter" << std::endl;
        TEST( barrier.enter( ));
        std::cerr << "Slave left" << std::endl;

        node->unmapObject( &barrier );
        node->close();
    }
Exemple #2
0
    virtual void run()
        {
            co::ConnectionDescriptionPtr description = 
                new co::ConnectionDescription;
            description->type = co::CONNECTIONTYPE_TCPIP;
            description->port = _master ? _port : _port+1;

            co::LocalNodePtr node = new co::LocalNode;
            node->addConnectionDescription( description );
            TEST( node->listen( ));

            if( _master )
            {
                co::Barrier barrier( node, 2 );
                node->registerObject( &barrier );
                TEST( barrier.isAttached( ));

                _barrier = &barrier;
                barrier.enter();

                _barrier.waitEQ( 0 ); // wait for slave to unmap session
                node->deregisterObject( &barrier );
            }
            else
            {
                _barrier.waitNE( 0 );

                co::NodePtr server = new co::Node;
                co::ConnectionDescriptionPtr serverDesc = 
                    new co::ConnectionDescription;
                serverDesc->port = _port;
                server->addConnectionDescription( serverDesc );
                TEST( node->connect( server ));

                std::cerr << "Slave enter" << std::endl;
                _barrier->enter();
                std::cerr << "Slave left" << std::endl;

                _barrier = 0;
            }

            node->close();
        }
Exemple #3
0
int main( int argc, char **argv )
{
    TEST( co::init( argc, argv ));

    MasterThread master;
    SlaveThread slave;

    master.start();
    slave.start();

    _barrier.waitNE( 0 );
    std::cerr << "Main enter" << std::endl;
    TEST( _barrier->enter( ));
    std::cerr << "Main left" << std::endl;

    slave.join();
    _barrier = 0;

    master.join();

    co::exit();
    return EXIT_SUCCESS;
}