Boost logo

Threads-Devel :

Subject: Re: [Threads-devel] Request Help On boost::lock_error
From: Stefan Küppers (kueppers_web_at_[hidden])
Date: 2010-09-14 10:36:59


Hi,
you should try "recursive_mutex" :
http://www.boost.org/doc/libs/1_32_0/doc/html/recursive_mutex.html

Regards,
Stefan.


Von: Ashutosh Warikoo <awarikoo@nse.co.in>
Gesendet: 14.09.2010 11:21:42
An: threads-devel@lists.boost.org
Betreff: [Threads-devel] Request Help On boost::lock_error


Hello
I am trying to model a usecase where a member function reads in a value & now has to modify the value by calling another function. The code which I have written using upgrade_locks fails at run time. I have gone through the documentation & have cleared the code as best as I could to arrive at a condensed usecase. I have also attached some sample erroneous outputs & a backtrace of the thread in question. Can someone please have a look?
 
Linux architecture_233 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
GNU C Library stable release version 2.5, by Roland McGrath et al.
Compiled by GNU CC version 4.1.2 20080704 (Red Hat 4.1.2-44).
Compiled on a Linux 2.6.9 system on 2009-01-05.
Available extensions:
        The C stubs add-on version 2.1.2.
         crypt add-on version 2.1 by Michael Glad and others
         GNU Libidn by Simon Josefsson
         GNU libio by Per Bothner
         NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
         Native POSIX Threads Library by Ulrich Drepper et al
         BIND-8.2.3-T5B
         RT using linux kernel aio
Thread-local storage support included.
 
#include <iostream>
#include <boost/thread.hpp>
class boostThreadLocksTest
{
        public:
                boost::shared_mutex myMutex;
                boost::upgrade_lock<boost::shared_mutex> myLock;
                static int firstFunction(boostThreadLocksTest *pBoostThreadLocksTest);
                static int secondFunction(boostThreadLocksTest *pBoostThreadLocksTest);
                boostThreadLocksTest():myMutex(),myLock(myMutex,boost::defer_lock_t()){};
};
int boostThreadLocksTest::firstFunction(boostThreadLocksTest *pBoostThreadLocksTest)
{
        std::cout<<"Before Locking           "<<boost::this_thread::get_id()<<" "<<__PRETTY_FUNCTION__<<std::endl;
        pBoostThreadLocksTest->myLock.lock();
        std::cout<<"After Locking            "<<boost::this_thread::get_id()<<" "<<__PRETTY_FUNCTION__<<std::endl;
        pBoostThreadLocksTest->secondFunction(pBoostThreadLocksTest);
        std::cout<<"Returned >From Call       "<<boost::this_thread::get_id()<<" "<<__PRETTY_FUNCTION__<<std::endl;
        pBoostThreadLocksTest->myLock.unlock();
        std::cout<<"After Unlocking          "<<boost::this_thread::get_id()<<" "<<__PRETTY_FUNCTION__<<std::endl;
        return(0);
}
int boostThreadLocksTest::secondFunction(boostThreadLocksTest *pBoostThreadLocksTest)
{
        std::cout<<"Before Exclusive Locking "<<boost::this_thread::get_id()<<" "<<__PRETTY_FUNCTION__<<std::endl;
        boost::upgrade_to_unique_lock<boost::shared_mutex> localUniqueLock(pBoostThreadLocksTest->myLock);
        std::cout<<"After Exclusive Locking  "<<boost::this_thread::get_id()<<" "<<__PRETTY_FUNCTION__<<std::endl;
        return(0);
}
int main()
{
        boostThreadLocksTest myObject;
        boost::thread_group myThreadGroup;
        myThreadGroup.create_thread(boost::bind(boostThreadLocksTest::firstFunction,&myObject));
        myThreadGroup.create_thread(boost::bind(boostThreadLocksTest::firstFunction,&myObject));
        myThreadGroup.create_thread(boost::bind(boostThreadLocksTest::firstFunction,&myObject));
        myThreadGroup.join_all();
}
 
Before Locking           0x7694120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
After Locking            0x7694120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Before Exclusive Locking 0x7694120 static int boostThreadLocksTest::secondFunction(boostThreadLocksTest*)
After Exclusive Locking  0x7694120 static int boostThreadLocksTest::secondFunction(boostThreadLocksTest*)
Returned From Call       0x7694120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
After Unlocking          0x7694120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Before Locking           0x76943e0 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
After Locking            0x76943e0 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Before Exclusive Locking 0x76943e0 static int boostThreadLocksTest::secondFunction(boostThreadLocksTest*)
After Exclusive Locking  0x76943e0 static int boostThreadLocksTest::secondFunction(boostThreadLocksTest*)
Before Locking           0x76946e0 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Returned From Call       0x76943e0 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
what():  boost::lock_error
Aborted
 
Before Locking           0x1888e120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
After Locking            0x1888e120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Before Exclusive Locking 0x1888e120 static int boostThreadLocksTest::secondFunction(boostThreadLocksTest*)
After Exclusive Locking  0x1888e120 static int boostThreadLocksTest::secondFunction(boostThreadLocksTest*)
Before Locking           0x1888e3e0 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Returned From Call       0x1888e120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
what():  boost::lock_error
Returned From Call       0x1888e120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Aborted
 
Before Locking           0x18f62120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
After Locking            0x18f62120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Before Exclusive Locking 0x18f62120 static int boostThreadLocksTest::secondFunction(boostThreadLocksTest*)
After Exclusive Locking  0x18f62120 static int boostThreadLocksTest::secondFunction(boostThreadLocksTest*)
Before Locking           0x18f623e0 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Returned From Call       0x18f62120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
what():  boost::lock_error
Returned From Call       0x18f62120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Aborted
 
Before Locking           0x1a2a1120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
After Locking            0x1a2a1120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Before Exclusive Locking 0x1a2a1120 static int boostThreadLocksTest::secondFunction(boostThreadLocksTest*)
After Exclusive Locking  0x1a2a1120 static int boostThreadLocksTest::secondFunction(boostThreadLocksTest*)
Before Locking           0x1a2a13e0 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Returned From Call       0x1a2a1120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
what():  boost::lock_error
Returned From Call       0x1a2a1120 static int boostThreadLocksTest::firstFunction(boostThreadLocksTest*)
Aborted
 
Program terminated with signal 6, Aborted.
[New process 9574]
[New process 9573]
[New process 9571]
#0  0x00000039f8430215 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00000039f8430215 in raise () from /lib64/libc.so.6
#1  0x00000039f8431cc0 in abort () from /lib64/libc.so.6
#2  0x00000039fa0bec44 in __gnu_cxx::__verbose_terminate_handler () from /usr/lib64/libstdc++.so.6
#3  0x00000039fa0bcdb6 in ?? () from /usr/lib64/libstdc++.so.6
#4  0x00000039fa0bcde3 in std::terminate () from /usr/lib64/libstdc++.so.6
#5  0x00000039fa0bceca in __cxa_throw () from /usr/lib64/libstdc++.so.6
#6  0x00000000004108cf in boost::throw_exception<boost::lock_error> ()
#7  0x000000000041a1a0 in boost::upgrade_lock<boost::shared_mutex>::lock ()
#8  0x0000000000405e19 in boostThreadLocksTest::firstFunction ()
#9  0x0000000000409c36 in boost::_bi::list1<boost::_bi::value<boostThreadLocksTest*> >::operator()<int, int (*)(boostThreadLocksTest*), boost::_bi::list0> ()
#10 0x0000000000409c74 in boost::_bi::bind_t<int, int (*)(boostThreadLocksTest*), boost::_bi::list1<boost::_bi::value<boostThreadLocksTest*> > >::operator() ()
#11 0x0000000000409c92 in boost::detail::thread_data<boost::_bi::bind_t<int, int (*)(boostThreadLocksTest*), boost::_bi::list1<boost::_bi::value<boostThreadLocksTest*> > > >::run ()
#12 0x00002b627c120bbb in thread_proxy () from /usr/local/lib/libboost_thread.so.1.43.0
#13 0x00000039f9006367 in start_thread () from /lib64/libpthread.so.0
#14 0x00000039f84d30ad in clone () from /lib64/libc.so.6
 
#0  0x00000039f84c56db in write () from /lib64/libc.so.6
#1  0x00000039f846ba63 in _IO_new_file_write () from /lib64/libc.so.6
#2  0x00000039f846b976 in _IO_new_do_write () from /lib64/libc.so.6
#3  0x00000039f846c0f4 in _IO_new_file_overflow () from /lib64/libc.so.6
#4  0x00000039f8469286 in putc () from /lib64/libc.so.6
#5  0x00000039fa08ff2f in std::ostream::put () from /usr/lib64/libstdc++.so.6
#6  0x00000039fa090010 in std::endl<char, std::char_traits<char> > () from /usr/lib64/libstdc++.so.6
#7  0x0000000000405d4a in boostThreadLocksTest::secondFunction ()
#8  0x0000000000405e9b in boostThreadLocksTest::firstFunction ()
#9  0x0000000000409c36 in boost::_bi::list1<boost::_bi::value<boostThreadLocksTest*> >::operator()<int, int (*)(boostThreadLocksTest*), boost::_bi::list0> ()
#10 0x0000000000409c74 in boost::_bi::bind_t<int, int (*)(boostThreadLocksTest*), boost::_bi::list1<boost::_bi::value<boostThreadLocksTest*> > >::operator() () #11 0x0000000000409c92 in boost::detail::thread_data<boost::_bi::bind_t<int, int (*)(boostThreadLocksTest*), boost::_bi::list1<boost::_bi::value<boostThreadLocksTest*> > > >::run ()
#12 0x00002b627c120bbb in thread_proxy () from /usr/local/lib/libboost_thread.so.1.43.0
#13 0x00000039f9006367 in start_thread () from /lib64/libpthread.so.0
#14 0x00000039f84d30ad in clone () from /lib64/libc.so.6
 
#0  0x00000039f900a899 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x00002b627c1224e7 in boost::thread::join () from /usr/local/lib/libboost_thread.so.1.43.0
#2  0x000000000041aa47 in boost::thread_group::join_all ()
#3  0x0000000000405be3 in main ()



Disclaimer note on content of this message including enclosure(s)and
attachments(s): The contents of this e-mail are the privileged and
confidential material of National Stock Exchange of India Limited
(NSE). The information is solely intended for the individual/entity
it is addressed to. If you are not the intended recipient of this
message, please be aware that you are not authorized in any which
way whatsoever to read, forward, print, retain, copy or disseminate
this message or any part of it. If you have received this e-mail in
error, we would request you to please notify the sender immediately
by return e-mail and delete it from your computer. This e-mail
message including attachment(s), if any, is believed to be free of
any virus and NSE is not responsible for any loss or damage arising
in any way from its use.
  

WEB.DE DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für    
nur 19,99 €/mtl.!* http://produkte.web.de/go/DSL_Doppel_Flatrate/2

_______________________________________________
threads-devel mailing list
threads-devel_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/threads-devel

___________________________________________________________
WEB.DE DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für
nur 19,99 &euro;/mtl.!* http://produkte.web.de/go/DSL_Doppel_Flatrate/2


Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk