upgrade_to_unique_lock doesn't compile with vc2010
Using Boost 1.43, this program: # include <boost/thread.hpp> int main() { boost::shared_mutex mutex; boost::upgrade_lock<boost::shared_mutex> lock(mutex); boost::upgrade_to_unique_lock<boost::shared_mutex> write_lock(lock); } ... produces this error when compiled with Visual C++ 2010: C:\Users\braden>cl /I include/boost-1_43 /MD /EHsc upgrade_to_unique_lock_test.cpp Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64 Copyright (C) Microsoft Corporation. All rights reserved. upgrade_to_unique_lock_test.cpp include/boost-1_43\boost/thread/locks.hpp(823) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'boost::unique_lock<Mutex>' (or there is no acceptable conversion) with [ Mutex=boost::shared_mutex ] include/boost-1_43\boost/thread/locks.hpp(659): could be 'boost::upgrade_lock<Mutex> &boost::upgrade_lock<Mutex>::operator =(boost::upgrade_lock<Mutex>&)' with [ Mutex=boost::shared_mutex ] include/boost-1_43\boost/thread/locks.hpp(710): or 'boost::upgrade_lock<Mutex> &boost::upgrade_lock<Mutex>::operator =(boost::detail::thread_move_t<T>)' with [ Mutex=boost::shared_mutex, T=boost::upgrade_lock<boost::shared_mutex> ] include/boost-1_43\boost/thread/locks.hpp(717): or 'boost::upgrade_lock<Mutex> &boost::upgrade_lock<Mutex>::operator =(boost::detail::thread_move_t<T>)' with [ Mutex=boost::shared_mutex, T=boost::unique_lock<boost::shared_mutex> ] while trying to match the argument list '(boost::upgrade_lock<Mutex>, boost::unique_lock<Mutex>)' with [ Mutex=boost::shared_mutex ] include/boost-1_43\boost/thread/locks.hpp(820) : while compiling class template member function 'boost::upgrade_to_unique_lock<Mutex>::~upgrade_to_unique_lock(void)' with [ Mutex=boost::shared_mutex ] upgrade_to_unique_lock_test.cpp(7) : see reference to class template instantiation 'boost::upgrade_to_unique_lock<Mutex>' being compiled with [ Mutex=boost::shared_mutex ] I've searched a bit for previous reports of this sort of thing and I haven't found any. Hopefully that means I'm just doing something wrong. -- Braden McDaniel <braden@endoframe.com>
Braden McDaniel <braden@endoframe.com> writes:
Using Boost 1.43, this program:
# include <boost/thread.hpp>
int main() { boost::shared_mutex mutex; boost::upgrade_lock<boost::shared_mutex> lock(mutex); boost::upgrade_to_unique_lock<boost::shared_mutex> write_lock(lock); }
... produces this error when compiled with Visual C++ 2010:
That is trac issue 2501. It was fixed post 1.43, so should be in 1.44. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
Hi How could I loop through the container to get all the keys. Eg: For(int i=0;i< beambook.count();++i) Or Beambook:: iter1 = beambook.begin(), iter2 = beambook.end(); My requirement is to loop through the size and list compositeKey vs list of element Ids Thanks, UJ // define a multi_index_container with a composite key on typedef multi_index_container< Beam_entry, indexed_by< //non-unique as some might have more than ids ordered_non_unique< composite_key< Beam_entry, member<Beam_entry,unsigned int,&Beam_entry::pid>, member<Beam_entry,double,&Beam_entry::orientX>, member<Beam_entry,double,&Beam_entry::orientY>, member<Beam_entry,double,&Beam_entry::orientZ>, member<Beam_entry,double,&Beam_entry::OffsetA>, member<Beam_entry,double,&Beam_entry::OffsetB> > >, ordered_unique< member<Beam_entry,unsigned int,&Beam_entry::eid> > >
beambook;
On Tuesday, June 01, 2010 5:41 AM, Uthpal Urubail wrote:
Hi How could I loop through the container to get all the keys. Eg: For(int i=0;i< beambook.count();++i) Or Beambook:: iter1 = beambook.begin(), iter2 = beambook.end();
My requirement is to loop through the size and list compositeKey vs list of element Ids
Thanks, UJ
// define a multi_index_container with a composite key on typedef multi_index_container< Beam_entry, indexed_by< //non-unique as some might have more than ids ordered_non_unique< composite_key< Beam_entry, member<Beam_entry,unsigned int,&Beam_entry::pid>, member<Beam_entry,double,&Beam_entry::orientX>, member<Beam_entry,double,&Beam_entry::orientY>, member<Beam_entry,double,&Beam_entry::orientZ>, member<Beam_entry,double,&Beam_entry::OffsetA>, member<Beam_entry,double,&Beam_entry::OffsetB> > >, ordered_unique< member<Beam_entry,unsigned int,&Beam_entry::eid> > >
beambook;
for (beambook::iterator iter = container.begin(), i_end = container.end(); iter != i_end; iter = container.upper_bound (get key from iter))
Thanks for the reply.. Let me put my requirement more clear. I want to loop through and get all the element Ids[ member<Beam_entry,unsigned int,&Beam_entry::eid>] which are having the same member values[pid, orientX, orientY, orientZ, OffsetA and OffsetB]. I am expecting the count of the container to give the count of unique member entries. Something like: for (beambook::iterator iter = pb.begin(), i_end = pb.end(); iter != i_end; iter = pb.upper_bound(iter->eid)) { //print pid, orientX, orientY, orientZ, OffsetA, OffsetB VS VECTOR of eid's; } Thanks Uthpal -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Andrew Holden Sent: Tuesday, June 01, 2010 7:10 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] multi_index_container for composite key On Tuesday, June 01, 2010 5:41 AM, Uthpal Urubail wrote:
Hi How could I loop through the container to get all the keys. Eg: For(int i=0;i< beambook.count();++i) Or Beambook:: iter1 = beambook.begin(), iter2 = beambook.end();
My requirement is to loop through the size and list compositeKey vs list of element Ids
Thanks, UJ
// define a multi_index_container with a composite key on typedef multi_index_container< Beam_entry, indexed_by< //non-unique as some might have more than ids ordered_non_unique< composite_key< Beam_entry, member<Beam_entry,unsigned int,&Beam_entry::pid>, member<Beam_entry,double,&Beam_entry::orientX>, member<Beam_entry,double,&Beam_entry::orientY>, member<Beam_entry,double,&Beam_entry::orientZ>, member<Beam_entry,double,&Beam_entry::OffsetA>, member<Beam_entry,double,&Beam_entry::OffsetB> > >, ordered_unique< member<Beam_entry,unsigned int,&Beam_entry::eid> > >
beambook;
for (beambook::iterator iter = container.begin(), i_end = container.end(); iter != i_end; iter = container.upper_bound (get key from iter)) _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Uthpal Urubail escribió:
Thanks for the reply.. Let me put my requirement more clear. I want to loop through and get all the element Ids[ member<Beam_entry,unsigned int,&Beam_entry::eid>] which are having the same member values[pid, orientX, orientY, orientZ, OffsetA and OffsetB]. I am expecting the count of the container to give the count of unique member entries.
I think this is what you're after: for(beambook::iterator iter=pb.begin(),i_end=pb.end();iter!=i_end;){ beambook::iterator iter_next=pb.upper_bound(pb.key_extractor()(*iter)); // the bunch of elements in [iter,iter_next) have the same // [pid,orientX,orientX,orientZ,OffsetA,OffsetB] do{ // print eid or whatever }while(++iter!=iter_next); } Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Hi I am looking for a composite key container. Though I found multi_index_container for composite key is the best I have few doubts in its use case: Question:01 class Book { public: size_t mID; size_t node[3]; }; How to add the below into multi_index_container? typedef multi_index_container< Book, indexed_by< ordered_unique< composite_key< Book, member<Book,size_t,&Book::node[0]>, member<Book,size_t,&Book::node[1]>, member<Book,size_t,&Book::node[2]> > >, ordered_unique< member<Book,size_t,&Book::mID> > >
beambook;
Question:02 My requirement is straight forward. I need to get the id by providing 3 nodes. Should I always need to create a data structure? [class Book] Can't I have something like below? typedef multi_index_container< size_t, indexed_by< ordered_unique< composite_key< size_t, size_t, size_t > >, ordered_unique< size_t > >
beambook;
Thanks, UJ
Uthpal Urubail escribió:
Hi
I am looking for a composite key container.
Though I found multi_index_container for composite key is the best I have few doubts in its use case:
*Question:01*
class Book
{
public:
size_t mID;
*size_t node[3];*
};
How to add the below into multi_index_container?
typedef multi_index_container<
Book,
indexed_by<
ordered_unique<
composite_key<
Book,
member<Book,size_t,&Book::node[0]>,
member<Book,size_t,&Book::node[1]>,
member<Book,size_t,&Book::node[2]>
>
>,
ordered_unique<
member<Book,size_t,&Book::mID>
>
>
beambook;
member<Book,size_t,&Book::node[0]> does not work for syntactic reasons (Book::node[0] is not a member of Book), but you can overcome this difficulty by using a custom key extractor (http://tinyurl.com/dafk2f ) just like this: template<int N> struct BookNodeExtractor { typedef size_t result_type; result_type operator()(const Book& b)const { return b.node[N]; } }; typedef multi_index_container< Book, indexed_by< ordered_unique< composite_key< Book, BookNodeExtractor<0>, BookNodeExtractor<1>, BookNodeExtractor<2> > >, ordered_unique< member<Book,size_t,&Book::mID> > >
beambook;
*Question:02*
My requirement is straight forward. I need to get the id by providing 3 nodes.
Should I always need to create a data structure? [class Book]
No, in fact you don't need to create a Book object. Suppose bb is a beambook and you want to retrieve the mID of an element in bb with nodes n0, n1 and n2. You only have to do the following: size_t mID=bb.find(boost::make_tuple(n0,n1,n2))->mID; As you can see, you simply pass a tuple with the values for the composite key, not a whole Book object. Hope this helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Joaquín M López Muñoz, Thanks for offering me the help. One interesting observation: If I use the below in finding the objects it is not retrieving properly indexed_by< ordered_unique< /// INSTEAD if I use ordered_non_unique< it works fine composite_key< I am still not clear with my question:2 Can I define the container like below? I don't want to create the temporary data structure. I will get these information from a class object. Can I use them directly?? Please help me in understanding. typedef multi_index_container< <pointer???>, //?? indexed_by< ordered_unique< composite_key< <pointer????>, //??? BookNodeExtractor<0>, BookNodeExtractor<1>, BookNodeExtractor<2> > >, ordered_unique< member<classname,size_t,&classname::id> > > > beambook; Thanks, UJ -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of joaquin@tid.es Sent: Thursday, September 09, 2010 11:31 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] multi_index_container for composite key Uthpal Urubail escribió:
Hi
I am looking for a composite key container.
Though I found multi_index_container for composite key is the best I have few doubts in its use case:
*Question:01*
class Book
{
public:
size_t mID;
*size_t node[3];*
};
How to add the below into multi_index_container?
typedef multi_index_container<
Book,
indexed_by<
ordered_unique<
composite_key<
Book,
member<Book,size_t,&Book::node[0]>,
member<Book,size_t,&Book::node[1]>,
member<Book,size_t,&Book::node[2]>
>
>,
ordered_unique<
member<Book,size_t,&Book::mID>
>
>
beambook;
member<Book,size_t,&Book::node[0]> does not work for syntactic reasons (Book::node[0] is not a member of Book), but you can overcome this difficulty by using a custom key extractor (http://tinyurl.com/dafk2f ) just like this: template<int N> struct BookNodeExtractor { typedef size_t result_type; result_type operator()(const Book& b)const { return b.node[N]; } }; typedef multi_index_container< Book, indexed_by< ordered_unique< composite_key< Book, BookNodeExtractor<0>, BookNodeExtractor<1>, BookNodeExtractor<2> > >, ordered_unique< member<Book,size_t,&Book::mID> > >
beambook;
*Question:02*
My requirement is straight forward. I need to get the id by providing 3 nodes.
Should I always need to create a data structure? [class Book]
No, in fact you don't need to create a Book object. Suppose bb is a beambook and you want to retrieve the mID of an element in bb with nodes n0, n1 and n2. You only have to do the following: size_t mID=bb.find(boost::make_tuple(n0,n1,n2))->mID; As you can see, you simply pass a tuple with the values for the composite key, not a whole Book object. Hope this helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Uthpal Urubail escribió:
Joaquín M López Muñoz, Thanks for offering me the help.
You're welcome. Please don't top-post and try to follow the general discussion policies outlined at http://www.boost.org/community/policy.html
One interesting observation: If I use the below in finding the objects it is not retrieving properly indexed_by< ordered_unique< /// INSTEAD if I use ordered_non_unique< it works fine composite_key<
If you use ordered_unique then there cannot be two elements with the same node[0], node[1], node[2] values. I guess this is what's happening in your case.
I am still not clear with my question:2 Can I define the container like below? I don't want to create the temporary data structure. I will get these information from a class object. Can I use them directly?? Please help me in understanding.
typedef multi_index_container< <pointer???>, //?? indexed_by< ordered_unique< composite_key< <pointer????>, //??? BookNodeExtractor<0>, BookNodeExtractor<1>, BookNodeExtractor<2> > >, ordered_unique< member<classname,size_t,&classname::id> > >
beambook;
I'm not sure what your question is, but if you wonder whether you can define a container of pointers to Books rather than Book objects proper, the answer is: you can, but you have to modify BookNodeExtractor so that it accepts pointers rather than Book &s. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Joaquín, My question is: Can I define container like below? typedef multi_index_container< ElemShell*, indexed_by< //non-unique as some might have more than ids ordered_non_unique< composite_key< ElemShell*, member<ElemShell,int,&ElemShell::N1>, member<ElemShell,int,&ElemShell::N2>, member<ElemShell,int,&ElemShell::N3>, member<ElemShell,int,&ElemShell::N4> > >, ordered_unique< member<GeneralElement,int,&GeneralElement::EID> > >
beambook;
When I retrieve, beambook::iterator it=(pb.find(boost::make_tuple(obj->N1,obj->N2,obj->N3,node4))); int val = (*it)->N4; Application is crashing. About: If you use ordered_unique then there cannot be two elements with the same node[0], node[1], node[2] values. Its TRUE. Two elements cannot have same node[0], node[1], node[2] values. How should be the container? Thanks, Uthpal
Uthpal Urubail escribió:
Joaquín, My question is: Can I define container like below? typedef multi_index_container< ElemShell*, indexed_by< //non-unique as some might have more than ids ordered_non_unique< composite_key< ElemShell*, member<ElemShell,int,&ElemShell::N1>, member<ElemShell,int,&ElemShell::N2>, member<ElemShell,int,&ElemShell::N3>, member<ElemShell,int,&ElemShell::N4> > >, ordered_unique< member<GeneralElement,int,&GeneralElement::EID> > >
beambook;
Yes, you can (except that the second index seems to be wrongly keyed on GeneralElement rather than ElemShell, but I understand this is a typo.)
When I retrieve, beambook::iterator it=(pb.find(boost::make_tuple(obj->N1,obj->N2,obj->N3,node4))); int val = (*it)->N4; Application is crashing.
Almost surely because there's no element with the provided N1,N2,N3,N4 and hence the iteraror it is pb.end().
About: If you use ordered_unique then there cannot be two elements with the same node[0], node[1], node[2] values. Its TRUE. Two elements cannot have same node[0], node[1], node[2] values. How should be the container?
Use ordered_unique then, as your own statements imply. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Hi I am new to multithreading please help me to resolve the below issue. I am getting the below error when I try to compile a simple multithreading program. 'libboost_thread-vc80-mt-gd-1_41.lib' - Is missing in boost installation. [**folder $BOOST_ROOT/stage is missing] 1>------ Build started: Project: BoostMultithreading, Configuration: Debug Win32 ------ 1>Compiling... 1>main.cpp 1>Linking... 1>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc80-mt-gd-1_41.lib' 1>BoostMultithreading - 1 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Thanks in advance UJ
AMDG Uthpal Urubail wrote:
I am new to multithreading please help me to resolve the below issue. I am getting the below error when I try to compile a simple multithreading program. 'libboost_thread-vc80-mt-gd-1_41.lib' - Is missing in boost installation. [**folder $BOOST_ROOT/stage is missing]
1>------ Build started: Project: BoostMultithreading, Configuration: Debug Win32 ------ 1>Compiling... 1>main.cpp 1>Linking... 1>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc80-mt-gd-1_41.lib' 1>BoostMultithreading - 1 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Have you read http://www.boost.org/more/getting_started/windows.html? In Christ, Steven Watanabe P.S. Please start a new thread instead of replying to an unrelated thread.
On Tue, 2010-06-01 at 07:48 +0100, Anthony Williams wrote:
Braden McDaniel <braden@endoframe.com> writes:
Using Boost 1.43, this program:
# include <boost/thread.hpp>
int main() { boost::shared_mutex mutex; boost::upgrade_lock<boost::shared_mutex> lock(mutex); boost::upgrade_to_unique_lock<boost::shared_mutex> write_lock(lock); }
... produces this error when compiled with Visual C++ 2010:
That is trac issue 2501. It was fixed post 1.43, so should be in 1.44.
Aha. Thanks. -- Braden McDaniel <braden@endoframe.com>
Hello, That is trac issue 2501. It was fixed post 1.43, so should be in 1.44.
Trunk version of locks.hpp does not compile this example with MSVC 2010. Do I need other files from trunk to fix this issue? I've attached patch that I did to fix this issue for me. (Should be applied to trunk version of locks.hpp) Best Regards, Sergei
participants (7)
-
Andrew Holden
-
Anthony Williams
-
Braden McDaniel
-
joaquin@tid.es
-
Sergei Politov
-
Steven Watanabe
-
Uthpal Urubail