This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for the producer_consumer test -> by Felix Yen.
- From: Dhruv Matani <dhruvbird at HotPOP dot com>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Cc: Felix Yen <fwy at alumni dot brown dot edu>,Loren James Rittle <rittle at labs dot mot dot com>,gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: 23 Mar 2004 20:42:37 +0530
- Subject: Patch for the producer_consumer test -> by Felix Yen.
- Organization:
Hello,
Here is a patch for the producer_consumer.cc test that Felix Yen had
conveyed to me by provate email, so it should probably be merged with
mainline. The message body said:
<Quoting>
I haven't looked at the code for a while, but the version I ghost wrote
had a bug in it that made it much slower than it should be. The
producer's algorithm should be linear, but it's quadratic in most
cases. Strictly speaking, the test is still fair, but it dilutes the
cost of allocating with excessive/unnecessary container traversals.
I'd start by modifying the test as follows. The body of the push_back
method should not call size(); instead, it should look something like
this:
<End Quote>
//See patch for more info.
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html
diff -Nrcp ./cvs_libstdc++-v3/.cvsignore ./modified_cvs_libstdc++/.cvsignore
*** ./cvs_libstdc++-v3/.cvsignore 2004-02-06 04:49:53.000000000 +0530
--- ./modified_cvs_libstdc++/.cvsignore 1970-01-01 05:30:00.000000000 +0530
***************
*** 1 ****
- autom4te.cache
--- 0 ----
diff -Nrcp ./cvs_libstdc++-v3/testsuite/performance/20_util/allocator/producer_consumer.cc ./modified_cvs_libstdc++/testsuite/performance/20_util/allocator/producer_consumer.cc
*** ./cvs_libstdc++-v3/testsuite/performance/20_util/allocator/producer_consumer.cc 2004-03-23 14:53:22.000000000 +0530
--- ./modified_cvs_libstdc++/testsuite/performance/20_util/allocator/producer_consumer.cc 2004-03-23 20:36:51.000000000 +0530
*************** template<typename Container>
*** 129,136 ****
Queue<Container>::push_back(const typename Container::value_type& value)
{
AutoLock auto_lock(lock);
queue.insert(queue.end(), value);
! if (queue.size() == 1) pthread_cond_signal(&condition);
}
template<typename Container>
--- 129,137 ----
Queue<Container>::push_back(const typename Container::value_type& value)
{
AutoLock auto_lock(lock);
+ const bool signal = queue.empty();
queue.insert(queue.end(), value);
! if (signal) pthread_cond_signal(&condition);
}
template<typename Container>