Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86545 - trunk/libs/thread/test
From: vicente.botet_at_[hidden]
Date: 2013-11-02 08:58:03


Author: viboes
Date: 2013-11-02 08:58:03 EDT (Sat, 02 Nov 2013)
New Revision: 86545
URL: http://svn.boost.org/trac/boost/changeset/86545

Log:
Thread: added new/old tickets tests for regression purposes.

Added:
   trunk/libs/thread/test/test_8455.cpp (contents, props changed)
   trunk/libs/thread/test/test_8557.cpp (contents, props changed)
   trunk/libs/thread/test/test_9192.cpp (contents, props changed)
   trunk/libs/thread/test/test_9319.cpp (contents, props changed)
Text files modified:
   trunk/libs/thread/test/Jamfile.v2 | 45 ++++++++----
   trunk/libs/thread/test/test_7720.cpp | 10 ++
   trunk/libs/thread/test/test_8455.cpp | 23 ++++++
   trunk/libs/thread/test/test_8557.cpp | 140 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/thread/test/test_8596.cpp | 2
   trunk/libs/thread/test/test_9079_b.cpp | 7 +
   trunk/libs/thread/test/test_9192.cpp | 140 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/thread/test/test_9319.cpp | 43 ++++++++++++
   8 files changed, 388 insertions(+), 22 deletions(-)

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 Sat Nov 2 05:58:33 2013 (r86544)
+++ trunk/libs/thread/test/Jamfile.v2 2013-11-02 08:58:03 EDT (Sat, 02 Nov 2013) (r86545)
@@ -279,6 +279,8 @@
           #[ thread-run test_7160.cpp ]
           [ thread-run test_7328.cpp ]
           [ thread-run test_7571.cpp ]
+ [ thread-run test_9319.cpp ]
+
     ;
 
 
@@ -777,31 +779,40 @@
 
     ;
 
+ explicit ts_more ;
+ test-suite ts_more
+ :
+ [ thread-run test_7666.cpp ]
+ [ thread-run test_7720.cpp ]
+ [ thread-run test_7755.cpp ]
+ [ thread-run test_8455.cpp ]
+ [ thread-run test_8508.cpp ]
+ #[ thread-run test_8557.cpp ]
+ [ thread-run test_8586.cpp ]
+ [ thread-run test_8943.cpp ]
+ [ thread-run test_8960.cpp ]
+ [ thread-run test_9079_a.cpp ]
+ [ thread-run test_9079_b.cpp ]
+ [ thread-run test_9192.cpp ]
+ ;
+
+ explicit ts_more_cpp11 ;
+ test-suite ts_more_cpp11
+ :
+ [ thread-run test_8596.cpp ]
+ [ thread-run test_8600.cpp ]
+ ;
+
     explicit ts_ ;
     test-suite ts_
     :
-
           #[ thread-run ../example/test_so.cpp ]
           #[ thread-run ../example/test_so2.cpp ]
-
- #[ compile virtual_noexcept.cpp ]
- #[ thread-run test_7720.cpp ]
- #[ thread-run test_7666.cpp ]
- #[ thread-run test_7755.cpp ]
           #[ thread-run ../example/perf_condition_variable.cpp ]
           #[ thread-run ../example/perf_shared_mutex.cpp ]
           #[ thread-run ../example/std_async_test.cpp ]
- #[ thread-run test_8508.cpp ]
- #[ thread-run test_8586.cpp ]
- #[ thread-run test_8596.cpp ]
- #[ thread-run test_8600.cpp ]
- #[ thread-run test_8943.cpp ]
- #[ thread-run test_8960.cpp ]
- #[ thread-run test_9079_a.cpp ]
- #[ thread-run test_9079_b.cpp ]
- #[ thread-run clang_main.cpp ]
- #[ thread-run test_8557.cpp ]
-
+ #[ compile virtual_noexcept.cpp ]
+ #[ thread-run clang_main.cpp ]
     ;
 
 }

Modified: trunk/libs/thread/test/test_7720.cpp
==============================================================================
--- trunk/libs/thread/test/test_7720.cpp Sat Nov 2 05:58:33 2013 (r86544)
+++ trunk/libs/thread/test/test_7720.cpp 2013-11-02 08:58:03 EDT (Sat, 02 Nov 2013) (r86545)
@@ -12,9 +12,11 @@
 
 shared_mutex mtx;
 
+const int max_count = 100;
 void f()
 {
- while (true)
+ int count =max_count;
+ while (count--)
     {
         upgrade_lock<shared_mutex> lock(mtx);
     }
@@ -22,7 +24,8 @@
 
 void g()
 {
- while (true)
+ int count =max_count;
+ while (count--)
     {
         shared_lock<shared_mutex> lock(mtx);
     }
@@ -30,7 +33,8 @@
 
 void h()
 {
- while (true)
+ int count =max_count;
+ while (count--)
     {
         unique_lock<shared_mutex> lock(mtx);
     }

Added: trunk/libs/thread/test/test_8455.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/thread/test/test_8455.cpp 2013-11-02 08:58:03 EDT (Sat, 02 Nov 2013) (r86545)
@@ -0,0 +1,23 @@
+// Copyright (C) 2013 Vicente Botet
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/thread/mutex.hpp>
+boost::mutex mut;
+void boostMutexImp1()
+{
+ boost::mutex::scoped_lock lock(mut);
+ mut.unlock(); // A: with this X blocks
+ //lock.unlock(); // No influence if used also if before A
+}
+void boostMutexImp2()
+{
+ boost::mutex::scoped_lock lock(mut); // X: blocks with A
+}
+int main()
+{
+ boostMutexImp1();
+ boostMutexImp2();
+ return 0;
+}

Added: trunk/libs/thread/test/test_8557.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/thread/test/test_8557.cpp 2013-11-02 08:58:03 EDT (Sat, 02 Nov 2013) (r86545)
@@ -0,0 +1,140 @@
+// Copyright (C) 2013 Vicente Botet
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// B
+
+#include <malloc.h>
+#include <boost/thread/thread.hpp>
+
+#include <boost/thread/mutex.hpp>
+
+#include <boost/bind.hpp>
+
+#include <iostream>
+
+ static void
+ display_mallinfo()
+ {
+ struct mallinfo mi;
+
+ mi = mallinfo();
+
+ printf("Total non-mmapped bytes (arena): %d\n", mi.arena);
+ printf("# of free chunks (ordblks): %d\n", mi.ordblks);
+ printf("# of free fastbin blocks (smblks): %d\n", mi.smblks);
+ printf("# of mapped regions (hblks): %d\n", mi.hblks);
+ printf("Bytes in mapped regions (hblkhd): %d\n", mi.hblkhd);
+ printf("Max. total allocated space (usmblks): %d\n", mi.usmblks);
+ printf("Free bytes held in fastbins (fsmblks): %d\n", mi.fsmblks);
+ printf("Total allocated space (uordblks): %d\n", mi.uordblks);
+ printf("Total free space (fordblks): %d\n", mi.fordblks);
+ printf("Topmost releasable block (keepcost): %d\n", mi.keepcost);
+ }
+
+boost::mutex io_mutex;
+
+void count() {
+
+ for (int i = 0; i < 10; ++i) {
+
+ boost::mutex::scoped_lock lock(io_mutex);
+
+ //boost::this_thread::sleep( boost::posix_time::milliseconds( 100 ) );
+
+ }
+
+}
+void* count2(void*) {
+
+ for (int i = 0; i < 10; ++i) {
+
+ boost::mutex::scoped_lock lock(io_mutex);
+
+ boost::this_thread::sleep( boost::posix_time::milliseconds( 100 ) );
+
+ }
+ return 0;
+}
+
+int main() {
+ printf("\n============== sizeof(boost::thread) ============== %d\n", sizeof(boost::thread));
+ printf("\n============== sizeof(boost::detail::thread_data_base) ============== %d\n", sizeof(boost::detail::thread_data_base));
+ printf("\n============== sizeof(boost::detail::thread_data<>) ============== %d\n", sizeof(boost::detail::thread_data<void(*)()>));
+ printf("\n============== Before thread creation ==============\n");
+ display_mallinfo();
+ {
+ boost::thread thrd1(&count);
+
+ printf("\n============== After thread creation ==============\n");
+ display_mallinfo();
+
+ boost::thread thrd2(&count);
+ printf("\n============== After thread creation ==============\n");
+ display_mallinfo();
+ boost::thread thrd3(&count);
+ printf("\n============== After thread creation ==============\n");
+ display_mallinfo();
+
+ thrd1.join();
+ printf("\n============== After thread join ==============\n");
+ display_mallinfo();
+
+ thrd2.join();
+ printf("\n============== After thread join ==============\n");
+ display_mallinfo();
+ thrd3.join();
+ printf("\n============== After thread join ==============\n");
+ display_mallinfo();
+ }
+ printf("\n============== After thread destruction ==============\n");
+ display_mallinfo();
+
+ {
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+
+ pthread_t thrd1;
+ pthread_create(&thrd1, &attr, &count2, 0);
+ printf("\n============== After thread creation ==============\n");
+ display_mallinfo();
+
+ pthread_t thrd2;
+ pthread_create(&thrd2, &attr, &count2, 0);
+ printf("\n============== After thread creation ==============\n");
+ display_mallinfo();
+
+ pthread_t thrd3;
+ pthread_create(&thrd3, &attr, &count2, 0);
+ printf("\n============== After thread creation ==============\n");
+ display_mallinfo();
+
+ pthread_attr_destroy(&attr);
+ printf("\n============== After thread attr destroy ==============\n");
+ display_mallinfo();
+
+ void* res;
+ pthread_join(thrd3, &res);
+ printf("\n============== After thread join ==============\n");
+ display_mallinfo();
+
+ pthread_join(thrd2, &res);
+ printf("\n============== After thread join ==============\n");
+ display_mallinfo();
+ pthread_join(thrd1, &res);
+ printf("\n============== After thread join ==============\n");
+ display_mallinfo();
+
+
+
+ //pthread_destroy(&thrd1);
+ //pthread_destroy(&thrd2);
+ //pthread_destroy(&thrd3);
+ }
+ printf("\n============== After thread destruction ==============\n");
+ display_mallinfo();
+
+ return 1;
+
+}

Modified: trunk/libs/thread/test/test_8596.cpp
==============================================================================
--- trunk/libs/thread/test/test_8596.cpp Sat Nov 2 05:58:33 2013 (r86544)
+++ trunk/libs/thread/test/test_8596.cpp 2013-11-02 08:58:03 EDT (Sat, 02 Nov 2013) (r86545)
@@ -7,7 +7,7 @@
 
 #include <iostream>
 #include <functional>
-#include <future>
+//#include <future>
 
 #include <boost/thread.hpp>
 #include <boost/shared_ptr.hpp>

Modified: trunk/libs/thread/test/test_9079_b.cpp
==============================================================================
--- trunk/libs/thread/test/test_9079_b.cpp Sat Nov 2 05:58:33 2013 (r86544)
+++ trunk/libs/thread/test/test_9079_b.cpp 2013-11-02 08:58:03 EDT (Sat, 02 Nov 2013) (r86545)
@@ -8,6 +8,7 @@
 #include <boost/atomic.hpp>
 //#include <boost/log/trivial.hpp>
 #include <boost/chrono.hpp>
+#include <boost/chrono/chrono_io.hpp>
 #include <boost/thread.hpp>
 #include <boost/thread/condition_variable.hpp>
 
@@ -59,7 +60,9 @@
 
   //BOOST_LOG_TRIVIAL(info) << "[TaskScheduler::run_and_wait] Scheduling loop - BEGIN";
 
- while (!foo.is_exiting()) {
+ int i =11;
+ while (i--)
+ {
     const TimePoint next_task_spawn_time = foo.spawn_tasks();
 
     const TimePoint now = real_time_now();
@@ -71,6 +74,8 @@
     const TimePoint::duration wait_time = next_spawn_time - now;
     if (wait_time > wait_time.zero()) {
       // BOOST_LOG_TRIVIAL(trace) << "WAIT TIME: " << wait_time; // UNCOMMENT THIS: MAKES IT WORKS. WAT??????
+ boost::this_thread::sleep_for(boost::chrono::seconds(1));
+ std::cout << next_spawn_time << std::endl;
       m_task_spawn_condition.wait_until(
           main_thread_lock,
           next_spawn_time); // DON'T WORK: WILL WAIT IF next_spawn_time is too close!

Added: trunk/libs/thread/test/test_9192.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/thread/test/test_9192.cpp 2013-11-02 08:58:03 EDT (Sat, 02 Nov 2013) (r86545)
@@ -0,0 +1,140 @@
+#include <boost/interprocess/shared_memory_object.hpp>
+#include <boost/interprocess/mapped_region.hpp>
+#include <boost/thread.hpp>
+
+using namespace boost::interprocess;
+
+struct item
+{
+ int i;
+};
+
+struct queue
+{
+ void put( const item& item )
+ {
+ boost::unique_lock<boost::mutex> lock(mutex);
+ while ( item_in )
+ cond_full.wait(lock);
+
+ item_ = item;
+ item_in = true;
+ cond_empty.notify_one();
+ }
+
+ void print()
+ {
+ boost::unique_lock<boost::mutex> lock(mutex);
+ while ( !item_in )
+ cond_empty.wait(lock);
+
+ item_in = false;
+ std::cout << item_.i << std::endl;
+ cond_full.notify_one();
+ }
+
+
+private:
+ //Mutex to protect access to the queue
+ boost::mutex mutex;
+
+ //Condition to wait when the queue is empty
+ boost::condition_variable cond_empty;
+
+ //Condition to wait when the queue is full
+ boost::condition_variable cond_full;
+
+ bool item_in;
+
+ //Items to fill
+ item item_;
+};
+
+void *addr;
+
+void printThread()
+{
+ //Erase previous shared memory and schedule erasure on exit
+ struct shm_remove
+ {
+ shm_remove() { shared_memory_object::remove("MySharedMemory"); }
+ ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
+ } remover;
+
+ //Create a shared memory object.
+ shared_memory_object shm(create_only,"MySharedMemory",read_write);
+
+ try
+ {
+// //Set size
+// shm.truncate(sizeof(queue));
+//
+// //Map the whole shared memory in this process
+// mapped_region region(shm,read_write);
+//
+// //Get the address of the mapped region
+// void *addr = region.get_address();
+
+ //Construct the shared structure in memory
+ queue *q = new (addr) queue;
+
+ do
+ {
+ q->print();
+ } while ( true );
+ }
+// catch(interprocess_exception &ex)
+// {
+// std::cout << ex.what() << std::endl;
+// }
+ catch(boost::thread_interrupted&)
+ {
+ std::cout << "interrupted" << std::endl;
+ }
+ catch(...)
+ {
+ std::cout << "exception" << std::endl;
+ }
+}
+
+int main()
+{
+ addr = new queue();
+ boost::thread t(printThread);
+
+ // give the thread time to create the shm
+ boost::this_thread::sleep( boost::posix_time::milliseconds( 1000 ) );
+
+// //Create a shared memory object.
+// shared_memory_object shm(open_only,"MySharedMemory",read_write);
+
+ try
+ {
+// //Map the whole shared memory in this process
+// mapped_region region(shm,read_write);
+//
+// //Get the address of the mapped region
+// void *addr = region.get_address();
+
+ //Obtain a pointer to the shared structure
+ queue *q = static_cast<queue*>(addr);
+
+ item i;
+ i.i = 42;
+ q->put( i );
+
+ ++i.i;
+ q->put( i );
+
+ // give the printThread time to "process" the item
+ boost::this_thread::sleep( boost::posix_time::milliseconds( 1000 ) );
+
+ t.interrupt();
+ t.join();
+ }
+ catch(...)
+ {
+ std::cout << "exception" << std::endl;
+ return -1;
+ }
+}

Added: trunk/libs/thread/test/test_9319.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/thread/test/test_9319.cpp 2013-11-02 08:58:03 EDT (Sat, 02 Nov 2013) (r86545)
@@ -0,0 +1,43 @@
+// Copyright (C) 2013 Vicente Botet
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// futtest.cpp
+#include <iostream>
+#define BOOST_THREAD_VERSION 4
+
+#include <boost/thread/future.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
+#include <boost/chrono.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
+
+using namespace boost;
+
+typedef shared_ptr< promise<int> > IntPromise;
+
+void foo(IntPromise p)
+{
+ std::cout << "foo" << std::endl;
+ p->set_value(123); // This line locks the future's mutex, then calls the continuation with the mutex already locked.
+}
+
+void bar(future<int> fooResult)
+{
+ std::cout << "bar" << std::endl;
+ int i = fooResult.get(); // Code hangs on this line (Due to future already being locked by the set_value call)
+ std::cout << "i: " << i << std::endl;
+}
+
+int main()
+{
+ IntPromise p(new promise<int>());
+ thread t(boost::bind(foo, p));
+ future<int> f1 = p->get_future();
+ //f1.then(launch::deferred, boost::bind(bar, _1));
+ f1.then(launch::deferred, &bar);
+ t.join();
+}
+


Boost-Commit 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