fill gap of boost/thread/read_write_mutex.hpp at1.46.1 and/or later
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
although I will try to contact authors(4
D.Ryan Stephens
Christopher Diggins
Jonathan Turkanis
Jeff Cogswell
, and I can only find email of second one, and I emailed him but never get him reply)
hope boost experts/programers take care on this problem a little bit more deeper
and like to see your post again to make this problem be fixed someway.
Eric
> Date: Thu, 4 Aug 2011 12:11:02 -0700
> From: brian.budge@gmail.com
> To: boost-users@lists.boost.org
> Subject: Re: [Boost-users] is boost 1.46.1 contain thread/read_write_mutex.hpp
>
> On Thu, Aug 4, 2011 at 11:52 AM, Eric Lin <kingdavid1@w.cn> wrote:
> >
> > Dear boost experts:
> >
so I follow your suggestion, add #include <
#include <boost/thread/shared_mutex.hpp>
---
but I still get compile error about
root@eric-laptop:/home/eric/cppcookbook/ch12# g++ -lboost_thread Example12-3.cpp
Example12-3.cpp:41:4: error: ‘read_wirte_mutex’ in namespace ‘boost’ does not name a type
------------
about the program segment on
-----
private:
std::list<T> list_;
boost::read_wirte_mutex rwMutex_;
};
-----------
do you (or any boost expert) know/suggest what kind function(subroutine) I can use to substitute it in share_mutex.hpp, so it still not deviate book author's main
intent of the program?
--------
another way is to copy in needed files
read_write_mutex.hpp
lock.hpp
read_write_lock.hpp
from web search and my compile error about
insufficient include file
, but then it come with many in compatiable
typedef, (and/or repeat) errors.
need your help and thanks a lot in advance, Eric
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > ----------------------------------------
> >> Date: Thu, 4 Aug 2011 08:30:50 -0700
> >> From: brian.budge@gmail.com
> >> To: boost-users@lists.boost.org
> >> Subject: Re: [Boost-users] is boost 1.46.1 contain thread/read_write_mutex.hpp
> >>
> >> On Wed, Aug 3, 2011 at 6:15 PM, Eric Lin <kingdavid1@w.cn> wrote:
> >> >
> >> > dear boost progamers:
> >> >
> >> > when I tried to compile from my g++4.5.2 a simple file which include
> >> > #include <boost/thread/read_write_mutex.hpp>
> >> > -------
> >> > root@eric-laptop:/home/eric/cppcookbook/ch12# g++ -lboost_thread Example12-3.cpp
> >> > Example12-3.cpp:3:45: fatal error: boost/thread/read_write_mutex.hpp: No such file or directory
> >> > compilation terminated.
> >> > ---------
> >> > and I check from / of my ubuntuLinux with boost 1.46.1
> >> > I can not find any file name as read_wirte_mutex.hpp
> >> > ---------
> >> > root@eric-laptop:/# find . | grep read_write_mutex.hpp
> >> > root@eric-laptop:/#
> >>
> >> It won't compile because that file does not exist. It sounds like
> >> you should get a new cppcookbook, given the number of examples you've
> >> posted about that are broken. You should probably first try emailing
> >> the author of that book regarding these problems. I believe you're
> >> looking for a shared_mutex.
> >>
> >> Brian
>
> The code is wrong, and we cannot divine the original author's intent.
> I suggest you contact the author regarding their broken code.
>
> Brian
> _______________________________________________
> Boost-users mailing list
> Boost-users@lists.boost.org
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
}
---------------------------------------------------------------------
this is copy from download
it actually a little bit different from book's(page 454), and this book is published at 05, 06
I hope linux experts can modify a little bit from it(not deviate from original code/intent of book author too much) but still work(at least, compile)
on my 1.46.1 of boost
hope it is nothing to do with gcc or linux
----
the book author claim(on page 453)
--
Using a mutex will get the job done, but it leaves a little to be desired. It makes no
distinction between reading and writing, which is significant, because it is inefficient
to force threads to wait in line to use a resource when many or all of them are doing a
read-only operation, which should be require exclusive access. For this, the Boost
Threads library provides read_write_mutex. Example 12-3 shows how you might
implement Example 12-2 using a read_write_mutex with a front member function
that allows the caller to retrieve a copy of the first item on the queue without pop
ping it.
--
and after the code, at page 455
--
There are a few things I should point out here. Notice that now I am using a read_
write_mutex, like this:
boost::read_write_mutex rwMutex_;
The locks are also different when you're using read/write mutexes. In Example 12-3,
when I want to lock the Queue for writing, I create a scoped_write_lock:
Read/write locks are handy, but they don't prevent you from shooting yourself in the
foot. There is no compile-time check on the resource represented by rwMutex_ to
make sure you're not changing it when you only have a read lock. Take extra care to
ensure a thread only modifies the state of an object when it has a write lock because
the compiler won't.
Please post your code within [CODE] <your code here> [ /CODE] tags!! It makes reading the code much easier. Also, when possible, try to reduce the size of the code such that it encompasses on the issue that you are trying to resolve. Something like the following would have sufficed (and note the CODE tags):
Code:
#include <boost/thread/read_write_mutex.hpp>
int main()
{
boost::read_write_mutex myMutex;
}
Now, as for the issue you have having, it is no doubt due to the deprecation of the read_write_mutex as of Boost 1.35 (read here at the very bottom of the page); you should instead rely on the shared_mutex.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.