Boost logo

Boost Users :

From: Andrew Wingorodov (andwing_at_[hidden])
Date: 2006-08-30 09:25:35


10x, sorry for my english

> I am not sure what this delay function does.

this function from ${BOOSTDIR}/libs/thread/test/util.inl

> scoped_time_lock takes boost::xtime or bool. 4 here is interpreted as
> "true", not as time.

oops.
okey, the new version of my cool program (how i can see event of timeout?) are
///------- COOLPRG
timed_mutex mut;
#define TIMEOUT 1
#define AUTHTIME 4

void
  timeout ()
{
        timed_mutex::scoped_timed_lock lk (mut, delay(TIMEOUT));
        if ( lk.locked ())
                cout << "how i can see event of timeout?" << endl;
        else
                cout << "okey!" << endl;
}
std::auto_ptr<timed_mutex::scoped_timed_lock> lock;
void
 auth ()
{
        cout << "auth" << endl;
        boost::thread::sleep ( delay(AUTHTIME));
        cout << "auth end" << endl;
        lock->unlock();
}

int
 main ()
{
        lock = (std::auto_ptr<timed_mutex::scoped_timed_lock>)
                new timed_mutex::scoped_timed_lock (mut,10);

        thread_group run;
        run.create_thread ( &auth);
        run.create_thread ( &timeout);
        run.create_thread ( &timeout);
        run.create_thread ( &timeout);

        run.join_all();

        if ( !lock->locked ())
                cout << "unlock!" << endl;
}
///EOF

And result (how i can see event of timeout?):

andr_at_andr> ./coolprg
auth
okey!
okey!
okey!
auth end
unlock!
andr_at_andr>

-- 
andr.ru

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net