Modify

Opened 9 years ago

Closed 5 years ago

#2501 closed Support Requests (fixed)

upgrade_to_unique_lock doesn't compile on C++0x mode

Reported by: Rodolfo Lima Owned by: viboes
Milestone: Component: thread
Version: Boost Development Trunk Severity: Problem
Keywords: move Cc: jwakely.boost@…, braden@…, viboes

Description

The following code doesn't compile with gcc-4.3.2 (and gcc-4.4.0), and boost-1.36 (and boost-1.37) when using -std=c++0x on linux.

#include <boost/thread/shared_mutex.hpp>

int main() {

boost::shared_mutex mtx; boost::upgrade_lock<boost::shared_mutex> lk(mtx);

boost::upgrade_to_unique_lock<boost::shared_mutex> lk2(lk);

}

gcc spits:

g++-4.4.0-alpha20081003 -std=c++0x -I src/boost-trunk teste.cpp -o teste In file included from src/boost-trunk/boost/thread/pthread/mutex.hpp:11,

from src/boost-trunk/boost/thread/mutex.hpp:16, from

src/boost-trunk/boost/thread/pthread/shared_mutex.hpp:12,

from src/boost-trunk/boost/thread/shared_mutex.hpp:16, from teste.cpp:1:

src/boost-trunk/boost/thread/locks.hpp: In destructor 'boost::upgrade_to_unique_lock<Mutex>::~upgrade_to_unique_lock() [with Mutex = boost::shared_mutex]': teste.cpp:8: instantiated from here src/boost-trunk/boost/thread/locks.hpp:807: error: no match for 'operator=' in '*((boost::upgrade_to_unique_lock<boost::shared_mutex>*)this)->boost::upgrade_to_unique_lock<boost::shared_mutex>::source

boost::move [with Mutex

boost::shared_mutex](((boost::unique_lock<boost::shared_mutex>&&)(&((boost::upgrade_to_unique_lock<boost::shared_mutex>*)this)->boost::upgrade_to_unique_lock<boost::shared_mutex>::exclusive)))' src/boost-trunk/boost/thread/locks.hpp:643: note: candidates are: boost::upgrade_lock<Mutex> & boost::upgrade_lock<Mutex>::operator=(boost::upgrade_lock<Mutex> &) [with Mutex = boost::shared_mutex] src/boost-trunk/boost/thread/locks.hpp:694: note: boost::upgrade_lock<Mutex> & boost::upgrade_lock<Mutex>::operator=(boost::detail::thread_move_t<boost::upgrade_lock<Mutex>

) [with Mutex = boost::shared_mutex]

src/boost-trunk/boost/thread/locks.hpp:701: note: boost::upgrade_lock<Mutex>& boost::upgrade_lock<Mutex>::operator=(boost::detail::thread_move_t<boost::unique_lock<Mutex>

) [with Mutex = boost::shared_mutex]

src/boost-trunk/boost/thread/locks.hpp: In constructor 'boost::unique_lock<Mutex>::unique_lock(boost::upgrade_lock<Mutex>&&) [with Mutex = boost::shared_mutex]': src/boost-trunk/boost/thread/locks.hpp:801: instantiated from 'boost::upgrade_to_unique_lock<Mutex>::upgrade_to_unique_lock(boost::upgrade_lock<Mutex>&) [with Mutex = boost::shared_mutex]' teste.cpp:8: instantiated from here src/boost-trunk/boost/thread/locks.hpp:775: error: request for member 'unlock_upgrade_and_lock' in '((boost::unique_lock<boost::shared_mutex>*)this)->boost::unique_lock<boost::shared_mutex>::m', which is of non-class type 'boost::shared_mutex*'

It compiles fine in non std++0x mode.

Regards, Rodolfo Lima

Attachments (1)

2501.patch (2.5 KB) - added by Jonathan Wakely <jwakely.boost@…> 8 years ago.
patch for boost/thread/locks.hpp

Download all attachments as: .zip

Change History (20)

comment:1 Changed 8 years ago by anonymous

This one still does not work :(

comment:2 Changed 8 years ago by Jonathan Wakely <jwakely.boost@…>

The last error is due to a trivial typo fixed by

--- boost-1_39/boost/thread/locks.hpp
+++ boost/thread/locks.hpp
@@ -772,7 +772,7 @@
         other.is_locked=false;
         if(is_locked)
         {
-            m.unlock_upgrade_and_lock();
+            m->unlock_upgrade_and_lock();
         }
     }
 #else

comment:3 Changed 8 years ago by Jonathan Wakely <jwakely.boost@…>

The second error is because upgrade_lock has no handling for the case when BOOST_HAS_RVALUE_REFS is defined. In that case boost::move() returns an rvalue reference rather than a boost::thread_move_t, but upgrade_lock can only handle the move wrapper, not an rvalue reference.

Changed 8 years ago by Jonathan Wakely <jwakely.boost@…>

patch for boost/thread/locks.hpp

comment:4 Changed 8 years ago by Jonathan Wakely <jwakely.boost@…>

  • Cc jwakely.boost@… added
  • Milestone changed from Boost 1.38.0 to Boost 1.40.0

that patch against boost 1.39.0 enables C++0x move support for upgrade_lock, fixing the testcase above.

Rodolfo, could you test it as well? It would be good to fix it for 1.40.0

comment:5 Changed 8 years ago by anonymous

Still there in 1.40

comment:6 Changed 7 years ago by anonymous

I applied the patch on 1.42 and after some minor adjustments it worked well, IMHO it's fine to go into 1.43.

comment:7 Changed 7 years ago by Rodolfo Lima

Any hope that it will get into 1.43?

comment:8 Changed 7 years ago by anthonyw

  • Resolution set to fixed
  • Status changed from new to closed

Fixed on trunk

comment:9 Changed 7 years ago by Braden McDaniel <braden@…>

  • Cc braden@… added
  • Milestone changed from Boost 1.40.0 to Boost 1.44.0
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from Boost Release Branch to Boost Development Trunk

comment:10 Changed 7 years ago by anonymous

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed on trunk

comment:11 follow-up: Changed 7 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

This still does not compile in vs2010 on trunk 1.44.0.

comment:12 Changed 7 years ago by viboes

  • Type changed from Bugs to Patches

Changed to Patch as patch exists.

comment:13 Changed 6 years ago by viboes

  • Milestone changed from Boost 1.44.0 to To Be Determined

comment:14 Changed 6 years ago by viboes

  • Type changed from Patches to Bugs

comment:15 in reply to: ↑ 11 Changed 6 years ago by viboes

  • Cc viboes added

Replying to anonymous:

This still does not compile in vs2010 on trunk 1.44.0.

Hi,

This ticket was for gcc-4.3.2 (and gcc-4.4.0). Please, even if this is an old ticket, could you post the errors you found now and post them here or even create another ticket and close this one?

comment:16 Changed 6 years ago by viboes

  • Owner changed from anthonyw to viboes
  • Status changed from reopened to new

I have tried with MSVC 2010 and it works

#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/locks.hpp>

int main() {
  boost::shared_mutex mtx; boost::upgrade_lock<boost::shared_mutex> lk(mtx);
  boost::upgrade_to_unique_lock<boost::shared_mutex> lk2(lk);
  return 0;
}

Could you try again on trunk?

comment:17 Changed 6 years ago by viboes

  • Type changed from Bugs to Support Requests

Moved to support request until resolution clarified

comment:18 Changed 6 years ago by viboes

  • Keywords move added

The is an action point to use Boost.Move. Could we consider this as a duplicate of #6194 Adapt to Boost.Move.

comment:19 Changed 5 years ago by viboes

  • Milestone To Be Determined deleted
  • Resolution set to fixed
  • Status changed from new to closed

Closed. Please reopen if this doesn't works on trunk 1.49.

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain viboes.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.