Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > boost::mutex - ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 16 Topic 43970 of 48022
Post > Topic >>

boost::mutex - are lock attempts queued?

by Lars Uffmann <aral@[EMAIL PROTECTED] > Mar 18, 2008 at 03:36 PM

I have 2 threads, master thread setting a keepalive flag, child thread 
checking that flag:

master thread function to end child thread:

   boost::mutex::scoped_lock lc (mutexAccessKeepalive, true);
   if (keepAlive)
     keepAlive = 0;
   lc.unlock();


child thread main loop:

   boost::mutex::scoped_lock lc (mutexAccessKeepalive, true);
   while (keepAlive) {
     lc.unlock();
     // do some stuff
     lc.lock();
   }
   lc.unlock();

In general, this works fine.
However, if the "// do some stuff" part (in this case listening for udp 
traffic) gets cut short (failed to bind socket) and exits fast, my 
master thread fails to acquire the lock on the mutex EVER. If I put a 
"sleep (1);" there, it works fine again and the child thread ends as 
intended.

I thought that attempts to lock an object were queued in boost, in the 
order the request was made? What happens here seems to indicate that my 
child thread is unlocking the mutex, and locks it again, before the main 
thread has a chance to "snatch" the lock.

Does anyone have an explanation and a workaround? :)

Best Regards,

    Lars
 




 16 Posts in Topic:
boost::mutex - are lock attempts queued?
Lars Uffmann <aral@[EM  2008-03-18 15:36:14 
Re: boost::mutex - are lock attempts queued?
Lars Uffmann <aral@[EM  2008-03-18 15:53:19 
Re: boost::mutex - are lock attempts queued?
Joe Greer <jgreer@[EMA  2008-03-18 17:27:54 
Re: boost::mutex - are lock attempts queued?
Lars Uffmann <aral@[EM  2008-03-18 17:42:09 
Re: boost::mutex - are lock attempts queued?
Lionel B <me@[EMAIL PR  2008-03-18 15:27:11 
Re: boost::mutex - are lock attempts queued?
Lars Uffmann <aral@[EM  2008-03-18 16:50:24 
Re: boost::mutex - are lock attempts queued?
Lionel B <me@[EMAIL PR  2008-03-18 16:02:54 
Re: boost::mutex - are lock attempts queued?
ytrembla@[EMAIL PROTECTED  2008-04-01 16:45:59 
Re: boost::mutex - are lock attempts queued?
Fei Liu <fei.liu@[EMAI  2008-03-18 11:29:08 
Re: boost::mutex - are lock attempts queued?
Lars Uffmann <aral@[EM  2008-03-18 16:53:37 
Re: boost::mutex - are lock attempts queued?
Paavo Helde <nobody@[E  2008-03-18 14:22:56 
Re: boost::mutex - are lock attempts queued?
Lars Uffmann <aral@[EM  2008-03-19 14:08:12 
Re: boost::mutex - are lock attempts queued?
Gerhard Fiedler <gelis  2008-03-19 10:43:46 
Re: boost::mutex - are lock attempts queued?
ytrembla@[EMAIL PROTECTED  2008-04-01 16:52:09 
Re: boost::mutex - are lock attempts queued?
Szabolcs Ferenczi <sza  2008-03-18 15:44:28 
Re: boost::mutex - are lock attempts queued?
Lars Uffmann <aral@[EM  2008-03-19 14:19:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 11:24:05 CDT 2008.