Boost logo

Boost-Commit :

From: doomster_at_[hidden]
Date: 2008-04-30 09:51:53


Author: eckhardt
Date: 2008-04-30 09:51:52 EDT (Wed, 30 Apr 2008)
New Revision: 44929
URL: http://svn.boost.org/trac/boost/changeset/44929

Log:
- Add include file to compile the thread library in-place.
- Add example file for in-place compiled thread library.

Added:
   sandbox/compile-in-place/Boost_1_35_0/boost/thread/compile_in_place.cpp (contents, props changed)
   sandbox/compile-in-place/test-threads.cpp (contents, props changed)

Added: sandbox/compile-in-place/Boost_1_35_0/boost/thread/compile_in_place.cpp
==============================================================================
--- (empty file)
+++ sandbox/compile-in-place/Boost_1_35_0/boost/thread/compile_in_place.cpp 2008-04-30 09:51:52 EDT (Wed, 30 Apr 2008)
@@ -0,0 +1,32 @@
+/* Copyright 2008 Ulrich Eckhardt
+
+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)
+*/
+// $Id$
+
+// This file must not be included more than once. Note that this 'once' is
+// not per translation unit but per binary! Never include this in a header!
+#ifdef BOOST_THREAD_COMPILE_IN_PLACE_CPP_INCLUDED
+# error "this file should only be included once per binary"
+#endif
+
+/* Note: this isn't a working include guard, but it's the best we can do here.
+If the user includes this in more than one translation unit they will simply
+get linker errors. */
+#define BOOST_THREAD_COMPILE_IN_PLACE_CPP_INCLUDED
+
+
+#if defined(BOOST_THREAD_PLATFORM_WIN32)
+# include "../../libs/thread/src/pthread/exceptions.cpp"
+# include "../../libs/thread/src/pthread/thread.cpp"
+# include "../../libs/thread/src/pthread/tss_dll.cpp"
+# include "../../libs/thread/src/pthread/tss_pe.cpp"
+#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
+# include "../../libs/thread/src/pthread/exceptions.cpp"
+# include "../../libs/thread/src/pthread/once.cpp"
+# include "../../libs/thread/src/pthread/thread.cpp"
+#else
+# error "Boost threads unavailable on this platform"
+#endif
+

Added: sandbox/compile-in-place/test-threads.cpp
==============================================================================
--- (empty file)
+++ sandbox/compile-in-place/test-threads.cpp 2008-04-30 09:51:52 EDT (Wed, 30 Apr 2008)
@@ -0,0 +1,84 @@
+/* example to demonstrate compile-in-place for threads
+
+Compile with
+ $CXX -I /path/to/boost_X_YY_Z test-threads.cpp -l $THREADLIBS
+
+
+$Id$
+*/
+
+#include <boost/thread.hpp>
+#include <iostream>
+#include <ostream>
+#include <boost/thread/compile_in_place.cpp>
+
+void delay( unsigned sec)
+{
+ boost::xtime xt;
+ boost::xtime_get( &xt, boost::TIME_UTC);
+ xt.sec += sec;
+ boost::thread::sleep(xt);
+}
+
+typedef boost::recursive_mutex mutex;
+typedef mutex::scoped_lock scoped_lock;
+
+mutex mtx;
+
+
+void thread1()
+{
+ std::cerr << "thread 1 entering\n";
+
+ delay(2);
+ {
+ std::cerr << "thread 1 acquiring mutex...\n";
+ scoped_lock lock(mtx);
+ std::cerr << "thread 1 acquired mutex\n";
+ delay(2);
+ std::cerr << "thread 1 releasing mutex\n";
+ }
+ delay(2);
+
+ std::cerr << "thread 1 leaving\n";
+}
+
+void thread2()
+{
+ std::cerr << "thread 2 entering\n";
+
+ delay(1);
+ {
+ std::cerr << "thread 2 acquiring mutex...\n";
+ scoped_lock lock(mtx);
+ std::cerr << "thread 2 acquired mutex\n";
+ delay(1);
+ std::cerr << "thread 2 releasing mutex\n";
+ }
+ delay(1);
+ {
+ std::cerr << "thread 2 acquiring mutex...\n";
+ scoped_lock lock(mtx);
+ std::cerr << "thread 2 acquired mutex\n";
+ delay(1);
+ std::cerr << "thread 2 releasing mutex\n";
+ }
+ delay(1);
+
+ std::cerr << "thread 2 leaving\n";
+}
+
+int main()
+{
+ std::cerr << "main() entering\n";
+
+ boost::thread th1(&thread1);
+ std::cerr << "main() thread 1 started\n";
+ boost::thread th2(&thread2);
+ std::cerr << "main() thread 2 started\n";
+ th1.join();
+ th2.join();
+
+ std::cerr << "main() leaving\n";
+}
+


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