Modify

Ticket #2501 (closed Support Requests: fixed)

Opened 5 years ago

Last modified 2 years ago

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

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

Change History

comment:1 Changed 5 years ago by anonymous

This one still does not work :(

comment:2 Changed 5 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 5 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 5 years ago by Jonathan Wakely <jwakely.boost@…>

patch for boost/thread/locks.hpp

comment:4 Changed 5 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 5 years ago by anonymous

Still there in 1.40

comment:6 Changed 4 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 4 years ago by Rodolfo Lima

Any hope that it will get into 1.43?

comment:8 Changed 4 years ago by anthonyw

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

Fixed on trunk

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

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

comment:10 Changed 4 years ago by anonymous

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

Fixed on trunk

comment:11 follow-up: ↓ 15 Changed 3 years ago by anonymous

  • Status changed from closed to reopened
  • Resolution fixed deleted

This still does not compile in vs2010 on trunk 1.44.0.

comment:12 Changed 3 years ago by viboes

  • Type changed from Bugs to Patches

Changed to Patch as patch exists.

comment:13 Changed 2 years ago by viboes

  • Milestone changed from Boost 1.44.0 to To Be Determined

comment:14 Changed 2 years ago by viboes

  • Type changed from Patches to Bugs

comment:15 in reply to: ↑ 11 Changed 2 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 2 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 2 years ago by viboes

  • Type changed from Bugs to Support Requests

Moved to support request until resolution clarified

comment:18 Changed 2 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 2 years ago by viboes

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

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
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.