Opened 14 years ago

Closed 11 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@…> 13 years ago.
patch for boost/thread/locks.hpp

Download all attachments as: .zip

Change History (20)

comment:1 by anonymous, 13 years ago

This one still does not work :(

comment:2 by Jonathan Wakely <jwakely.boost@…>, 13 years ago

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 by Jonathan Wakely <jwakely.boost@…>, 13 years ago

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.

by Jonathan Wakely <jwakely.boost@…>, 13 years ago

Attachment: 2501.patch added

patch for boost/thread/locks.hpp

comment:4 by Jonathan Wakely <jwakely.boost@…>, 13 years ago

Cc: jwakely.boost@… added
Milestone: Boost 1.38.0Boost 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 by anonymous, 13 years ago

Still there in 1.40

comment:6 by anonymous, 13 years ago

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 by Rodolfo Lima, 13 years ago

Any hope that it will get into 1.43?

comment:8 by Anthony Williams, 13 years ago

Resolution: fixed
Status: newclosed

Fixed on trunk

comment:9 by Braden McDaniel <braden@…>, 12 years ago

Cc: braden@… added
Milestone: Boost 1.40.0Boost 1.44.0
Resolution: fixed
Status: closedreopened
Version: Boost Release BranchBoost Development Trunk

comment:10 by anonymous, 12 years ago

Resolution: fixed
Status: reopenedclosed

Fixed on trunk

comment:11 by anonymous, 12 years ago

Resolution: fixed
Status: closedreopened

This still does not compile in vs2010 on trunk 1.44.0.

comment:12 by viboes, 12 years ago

Type: BugsPatches

Changed to Patch as patch exists.

comment:13 by viboes, 11 years ago

Milestone: Boost 1.44.0To Be Determined

comment:14 by viboes, 11 years ago

Type: PatchesBugs

in reply to:  11 comment:15 by viboes, 11 years ago

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 by viboes, 11 years ago

Owner: changed from Anthony Williams to viboes
Status: reopenednew

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 by viboes, 11 years ago

Type: BugsSupport Requests

Moved to support request until resolution clarified

comment:18 by viboes, 11 years ago

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 by viboes, 11 years ago

Milestone: To Be Determined
Resolution: fixed
Status: newclosed

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

Note: See TracTickets for help on using tickets.