Boost logo

Boost Users :

From: Andrew Wingorodov (andwing_at_[hidden])
Date: 2006-08-28 07:41:23


Why result of my program such?
auth() sleeps one second, and I have established four in timeout.
I thought, that will be "okey".
why timeout?

# ./a
auth
auth end
timeout!
timeout!
timeout!
#

///-----------------------------
static timed_mutex mut;
void timeout ()
{
       timed_mutex::scoped_timed_lock lk (mut,4);
       if ( lk.locked ())
               cout << "timeout!" << endl;
       else
               cout << "okey!" << endl;
}

timed_mutex::scoped_timed_lock *lock;

void auth ()
{
       cout << "auth" << endl;
       boost::thread::sleep ( delay(1));
       cout << "auth end" << endl;
       delete lock;
}

int
 main ()
{
       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();
}

-- 
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