Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 31,465 of 33,346    |
|    Ulrich Eckhardt to Chris M. Thomasson    |
|    Re: Weird problem with mutex and lock er    |
|    14 Sep 11 01:47:56    |
   
   From: ulrich.eckhardt@dominolaser.com   
      
   Chris M. Thomasson wrote:   
   > AFAICT, the recursive locking of the mutex is most definitely "intended";   
   > how else does one explain the following function's:   
   > ____________________________________________________________   
   > bool empty() const   
   > {   
   > boost::mutex::scoped_lock lock(the_mutex);   
   > return the_queue.empty();   
   > }   
   >   
   > bool try_pop(Data& popped_value)   
   > {   
   > boost::mutex::scoped_lock lock(the_mutex);   
   > if(the_queue.empty())   
   > {   
   > return false;   
   > }   
   >   
   > popped_value=the_queue.front();   
   > the_queue.pop();   
   > return true;   
   > }   
   > ____________________________________________________________   
   >   
   >   
   > AFAICT, `try_pop()' does lock the mutex twice... ;^o   
      
   It does check if the queue is empty, but it doesn't use its memberfunction   
   for that but directly accesses the internal container. So no, it doesn't.   
      
   Or am I missing something?   
      
   Uli   
      
   --   
   Domino Laser GmbH   
   Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932   
      
      
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca