osdir.com
mailing list archive
Mozy Online Backup: 2GB Free. Automatic. Secure.

Subject: condition notify_all problem - msg#00195

List: lib.boost.user

Date: Prev Next Index Thread: Prev Next Index
I've just started using the boost libraries, threads so far -- great
libraries. I have a test app that uses thread groups of producers
and consumers working with a queue. It seems simple enough, but I'm
encountering a deadlock problem using notify_all() vs looping with
notify_one() when ending the consumer threads. I'm not sure my
implementation is correct though (link to source below).

I can reliably cause deadlocks on all Windows XP systems I've tried
(single, dual and quad machines) within about a minute of
execution. However, I only had one deadlock on Windows 2000 (single
or quad) in over 6 hours of execution and still going.

Attaching or running the executable in the VS7 debugger shows all
the threads and the main thread stopped in ntdll.dll via
kernel32.dll. The stack shows the last user code executed by wmain
was boost::thread_group::join_all from ctg.join_all(). The threads
last ran boost::condition::do_wait before entering the kernel.

Swapping lines 217-218 for 222-227 appears to fix the deadlock by
looping with notify_one(). I would guess that something fundamental
is wrong with my implementation, and my fix just changes the
timing. Any help is appreciated.

The source is posted at the link below. I can provide further
information if necessary.

Thanks,
Joshua Boelter

www.boelter.org/data/t_threadgroup.cpp

Using Visual Studio 7.0.9466, stlport 4.5.3 (dll), boost libraries
1.29.0 on various WinXP Pro and Win2k systems.



Info: <http://www.boost.org>
Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
Unsubscribe: <mailto:boost-users-unsubscribe@xxxxxxxxxxxxxxx>


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/





Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

RE: using 'this' with shared_ptrs

You initialises two shared_ptr with the same raw pointer. As a consequent the destructor is called twice, as you will have two different shared_count object which will calls delete as the count become zero. Try to use weak_ptr as a member: ----------------------------------- typedef shared_ptr<MyClass> MyClassPtr; class MyClass { public: MyClass(); ~MyClass(); void setOriginal(MyClassPtr); MyClassPtr makeCopy(); weak_ptr<MyClass> original; }; MyClass::MyClass() { cout << "constructor called " << this << endl; } MyClass::~MyClass() { cout << "destructor called " << this << endl; } void MyClass::setOriginal(MyClassPtr p) { original = p; } MyClassPtr MyClass::makeCopy() { return MyClassPtr(original); } main() { MyClassPtr oc(new MyClass); oc->setOriginal(oc); MyClassPtr cc = oc->makeCopy(); } --------------------------------- Per -----Original Message----- From: Stephen Crowley [mailto:stephenc@xxxxxxxxxxxxxxxxxx] Sent: 15. november 2002 05:37 To: Boost-Users@xxxxxxxxxxxxxxx Subject: [Boost-Users] using 'this' with shared_ptrs How is someone supposed to use 'this' when setting a member of another class to point back to it? Here is an example.. when you run it, this will happen. constructor called 0x804af10 constructor called 0x804af48 destructor called 0x804af48 destructor called 0x804af10 destructor called 0x804af10 The last destructor is called twice! The only way I can think to get around this add a member to the class called "shared_ptr<MyClass> thisptr" which is initialized to "this" in the constructor and over-ride the assignment operator or something.. will that work? ------------------------ #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> #include <iostream> using namespace std; using namespace boost; class MyClass; typedef shared_ptr<MyClass> MyClassPtr; class MyClass { public: MyClass(); ~MyClass(); MyClassPtr makeCopy(); MyClassPtr original; }; MyClass::MyClass() { cout << "constructor called " << this << endl; } MyClass::~MyClass() { cout << "destructor called " << this << endl; } MyClassPtr MyClass::makeCopy() { MyClassPtr mc(new MyClass); mc->original = MyClassPtr(this); return mc; } main() { MyClassPtr oc(new MyClass); MyClassPtr cc = oc->makeCopy(); // the problem lies here // when cc's reference count is 0 it will be deleted, which will // in turn decrease its 'original' reference count which will be 0, thus // causing it to be deleted as well even though it is still being used by oc! cc.reset(); } ----------------------------------- -- Stephen Info: < http://www.boost.org> Wiki: < http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl> Unsubscribe: <mailto:boost-users-unsubscribe@xxxxxxxxxxxxxxx> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service <http://docs.yahoo.com/info/terms/> . [Non-text portions of this message have been removed] ------------------------ Yahoo! Groups Sponsor ---------------------~--> Share the magic of Harry Potter with Yahoo! Messenger http://us.click.yahoo.com/4Q_cgB/JmBFAA/46VHAA/EbFolB/TM ---------------------------------------------------------------------~-> Info: <http://www.boost.org> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl> Unsubscribe: <mailto:boost-users-unsubscribe@xxxxxxxxxxxxxxx> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

Next Message by Date: click to view message preview

uBlass outer_product

Hi, I can't get the following snipped from the doc examples to work: #include <iostream> #include <boost/numeric/ublas/vector.hpp> #include <boost/numeric/ublas/io.hpp> int main () { using namespace boost::numeric::ublas; vector<double> v1 (3), v2 (3); for (int i = 0; i < std::min (v1.size (), v2.size ()); ++ i) v1 (i) = v2 (i) = i; std::cout << outer_prod (v1, v2) << std::endl; } ublas_cross.cc: In function `int main()': ublas_cross.cc:17: `outer_prod' undeclared (first use this function) ublas_cross.cc:17: (Each undeclared identifier is reported only once for each function it appears in.) What's wrong here? Thanks Olaf ------------------------ Yahoo! Groups Sponsor ---------------------~--> Share the magic of Harry Potter with Yahoo! Messenger http://us.click.yahoo.com/4Q_cgB/JmBFAA/46VHAA/EbFolB/TM ---------------------------------------------------------------------~-> Info: <http://www.boost.org> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl> Unsubscribe: <mailto:boost-users-unsubscribe@xxxxxxxxxxxxxxx> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

Previous Message by Thread: click to view message preview

using 'this' with shared_ptrs

How is someone supposed to use 'this' when setting a member of another class to point back to it? Here is an example.. when you run it, this will happen. constructor called 0x804af10 constructor called 0x804af48 destructor called 0x804af48 destructor called 0x804af10 destructor called 0x804af10 The last destructor is called twice! The only way I can think to get around this add a member to the class called "shared_ptr<MyClass> thisptr" which is initialized to "this" in the constructor and over-ride the assignment operator or something.. will that work? ------------------------ #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> #include <iostream> using namespace std; using namespace boost; class MyClass; typedef shared_ptr<MyClass> MyClassPtr; class MyClass { public: MyClass(); ~MyClass(); MyClassPtr makeCopy(); MyClassPtr original; }; MyClass::MyClass() { cout << "constructor called " << this << endl; } MyClass::~MyClass() { cout << "destructor called " << this << endl; } MyClassPtr MyClass::makeCopy() { MyClassPtr mc(new MyClass); mc->original = MyClassPtr(this); return mc; } main() { MyClassPtr oc(new MyClass); MyClassPtr cc = oc->makeCopy(); // the problem lies here // when cc's reference count is 0 it will be deleted, which will // in turn decrease its 'original' reference count which will be 0, thus // causing it to be deleted as well even though it is still being used by oc! cc.reset(); } ----------------------------------- -- Stephen Info: <http://www.boost.org> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl> Unsubscribe: <mailto:boost-users-unsubscribe@xxxxxxxxxxxxxxx> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

Next Message by Thread: click to view message preview

Re: condition notify_all problem

Mike Wilson provided me with a concise example the reproduces the problem on a wider variety of systems. I uploaded slightly modified version of that source to the group files. I'm ready to blame it on the OS :) If anyone else has any insight, it's appreciated. Thanks, Joshua Boelter http://groups.yahoo.com/group/Boost- Users/files/condition/notifyall.cpp ------------------------ Yahoo! Groups Sponsor ---------------------~--> Get 128 Bit SSL Encryption! http://us.click.yahoo.com/JjlUgA/vN2EAA/xGHJAA/EbFolB/TM ---------------------------------------------------------------------~-> Info: <http://www.boost.org> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl> Unsubscribe: <mailto:boost-users-unsubscribe@xxxxxxxxxxxxxxx> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by