From f64208ce7ad9fe59a09979cb67d58762f39cb1cd Mon Sep 17 00:00:00 2001 From: "William E. Kempf" Date: Wed, 12 Sep 2001 21:29:42 +0000 Subject: [PATCH] Third round of changes from the review. [SVN r11109] --- doc/call_once.html | 2 + doc/condition.html | 54 ++++++++--------- doc/mutex.html | 23 +++---- doc/recursive_mutex.html | 17 +++--- doc/scoped_lock.html | 16 +++-- doc/scoped_timed_lock.html | 16 +++-- doc/scoped_try_lock.html | 16 +++-- doc/semaphore.html | 5 +- doc/thread.html | 11 +++- doc/thread_specific_ptr.html | 5 +- .../thread/{xlock.hpp => detail/lock.hpp} | 24 ++++---- include/boost/thread/mutex.hpp | 2 +- include/boost/thread/once.hpp | 2 +- include/boost/thread/recursive_mutex.hpp | 2 +- include/boost/thread/thread.hpp | 3 +- include/boost/thread/xtime.hpp | 2 +- src/condition.cpp | 2 - src/mutex.cpp | 14 ----- src/recursive_mutex.cpp | 18 ------ src/semaphore.cpp | 6 -- src/thread.cpp | 12 ++-- src/threadmon.cpp | 4 ++ src/timeconv.inl | 60 +++++++++---------- src/tss.cpp | 4 -- src/xtime.cpp | 2 +- 25 files changed, 153 insertions(+), 169 deletions(-) rename include/boost/thread/{xlock.hpp => detail/lock.hpp} (92%) diff --git a/doc/call_once.html b/doc/call_once.html index b992d448..3a6f8dba 100644 --- a/doc/call_once.html +++ b/doc/call_once.html @@ -74,6 +74,8 @@ to indicate that the logically associated routine has not been run yet.

void call_once(void (*func)(), once_flag& flag); +

Requires: The function func shall not throw exceptions.

+

Effects: As if (in an atomic fashion)

diff --git a/doc/condition.html b/doc/condition.html index 0d463301..a40666ea 100644 --- a/doc/condition.html +++ b/doc/condition.html @@ -65,7 +65,8 @@ for blocked.

 namespace boost { 
 
-class condition : private boost::noncopyable
+class condition : private boost::noncopyable // Exposition only.
+   // Class condition meets the NonCopyable requirement.
 {
 public:
    condition();
@@ -73,14 +74,14 @@ public:
 
    void notify_one();
    void notify_all();
-   template <typename ScopedLock>
-      void wait(ScopedLock& lock);
-   template <typename ScopedLock, typename Predicate>
-      void wait(ScopedLock& lock, Predicate pred);
-   template <typename ScopedTimedLock>
-      bool timed_wait(ScopedTimedLock& lock, const xtime& xt);
-   template <typename ScopedTimedLock, typename Predicate>
-      bool timed_wait(ScopedTimedLock& lock, const xtime& xt, Predicate pred);
+   template <typename ScopedLock>
+      void wait(ScopedLock& lock);
+   template <typename ScopedLock, typename Predicate>
+      void wait(ScopedLock& lock, Predicate pred);
+   template <typename ScopedLock>
+      bool timed_wait(ScopedLock& lock, const xtime& xt);
+   template <typename ScopedLock, typename Predicate>
+      bool timed_wait(ScopedLock& lock, const xtime& xt, Predicate pred);
 };
 
 } // namespace boost
@@ -147,7 +148,7 @@ template <typename ScopedLock>
 
 

Effects: Releases the lock on the mutex model associated with lock, blocks the current thread of execution until readied -by a call to *this->notify_one() or *this->notify_all(), +by a call to this->notify_one() or this->notify_all(), and then reacquires the lock. All effects occur in an atomic fashion.

Throws: lock_error @@ -190,8 +191,8 @@ template <typename ScopedTimedLock>

Effects: Releases the lock on the mutex model associated with the lock, blocks the current thread of execution until -readied by a call to *this->notify_one() or -*this->notify_all(), or until xt, and then reacquires the +readied by a call to this->notify_one() or +this->notify_all(), or until xt, and then reacquires the lock. All effects occur in an atomic fashion.

Throws: lock_error if @@ -205,7 +206,6 @@ encapsulates this loop idiom internally and is generally the preferred method.Returns: false if xt is reached, otherwise true.

-
 template <typename ScopedTimedLock, typename Pr>
    bool timed_wait(ScopedTimedLock& lock, const xtime& xt, Pr pred);
@@ -244,16 +244,10 @@ return from pred() convertible to bool.

class bounded_buffer : private boost::noncopyable { -private: - int begin, end, buffered; - std::vector<int> circular_buf; - boost::condition buffer_not_full, buffer_not_empty; - boost::mutex monitor; - - typedef boost::mutex::lock lock; - public: - buffer(int n) : begin(0), end(0), buffered(0), circular_buf(n) { } + typedef boost::mutex::scoped_lock lock; + + bounded_buffer(int n) : begin(0), end(0), buffered(0), circular_buf(n) { } void send (int m) { lock lk(monitor); @@ -266,7 +260,7 @@ public: } int receive() { lock lk(monitor); - while (buffered == 0 && !finished) + while (buffered == 0) buffer_not_empty.wait(lk); int i = circular_buf[begin]; begin = (begin+1) % circular_buf.size(); @@ -274,11 +268,17 @@ public: buffer_not_full.notify_one(); return i; } + +private: + int begin, end, buffered; + std::vector<int> circular_buf; + boost::condition buffer_not_full, buffer_not_empty; + boost::mutex monitor; }; bounded_buffer buf(2); -void sender(void*) { +void sender() { int n = 0; while (n < 100) { buf.send(n); @@ -288,7 +288,7 @@ void sender(void*) { buf.send(-1); } -void receiver(void*) { +void receiver() { int n; do { n = buf.receive(); @@ -298,8 +298,8 @@ void receiver(void*) { int main(int, char*[]) { - boost::thread thrd1(&sender, 0); - boost::thread thrd2(&receiver, 0); + boost::thread thrd1(&sender); + boost::thread thrd2(&receiver); thrd1.join(); thrd2.join(); return 0; diff --git a/doc/mutex.html b/doc/mutex.html index d7883062..1343b929 100644 --- a/doc/mutex.html +++ b/doc/mutex.html @@ -110,7 +110,8 @@ the lock in a random order, even though the specific behavior for a given platfo
 namespace boost
 {
-    class mutex : private boost::noncopyable
+    class mutex : private boost::noncopyable // Exposition only.
+        // Class mutex meets the NonCopyable requirement.
     {
     public:
         typedef [implementation defined; see Introduction] scoped_lock;
@@ -148,7 +149,7 @@ namespace boost
 

Effects: Destroys *this.

Dangers: Destruction of a locked mutex is a serious programming error -resulting in undefined behavior such as a program crash..

+resulting in undefined behavior such as a program crash.


@@ -159,7 +160,8 @@ resulting in undefined behavior such as a program crash..

 namespace boost
 {
-    class try_mutex : private boost::noncopyable
+    class try_mutex : private boost::noncopyable // Exposition only.
+        // Class try_mutex meets the NonCopyable requirement.
     {
     public:
         typedef [implementation defined; see Introduction] scoped_lock;
@@ -196,7 +198,7 @@ namespace boost
 

Effects: Destroys *this.

Dangers: Destruction of a locked mutex is a serious programming error -resulting in undefined behavior such as a program crash..

+resulting in undefined behavior such as a program crash.


@@ -207,7 +209,8 @@ resulting in undefined behavior such as a program crash..

 namespace boost
 {
-    class timed_mutex : private boost::noncopyable
+    class timed_mutex : private boost::noncopyable // Exposition only.
+        // Class timed_mutex meets the NonCopyable requirement.
     {
     public:
         typedef [implementation defined; see Introduction] scoped_lock;
@@ -245,7 +248,7 @@ namespace boost
 

Effects: Destroys *this.

Dangers: Destruction of a locked mutex is a serious programming error -resulting in undefined behavior such as a program crash..

+resulting in undefined behavior such as a program crash.


@@ -260,10 +263,6 @@ boost::mutex io_mutex; // The iostreams are not guaranteed to be boost::noncopyable + class recursive_mutex : private boost::noncopyable // Exposition only. + // Class recursive_mutex meets the NonCopyable requirement. { public: typedef [implementation defined; see Introduction] scoped_lock; @@ -163,7 +164,8 @@ Class recursive_try_mutex Synopsis
 namespace boost
 {
-    class recursive_try_mutex : private boost::noncopyable
+    class recursive_try_mutex : private boost::noncopyable // Exposition only.
+        // Class recursive_try_mutex meets the NonCopyable requirement.
     {
     public:
        typedef [implementation defined; see Introduction] scoped_lock;
@@ -211,7 +213,8 @@ Class recursive_timed_mutex Synopsis
 namespace boost
 {
-    class recursive_timed_mutex : private boost::noncopyable
+    class recursive_timed_mutex : private boost::noncopyable // Exposition only.
+        // Class recursive_timed_mutex meets the NonCopyable requirement.
     {
     public:
        typedef [implementation defined; see Introduction] scoped_lock;
@@ -264,10 +267,6 @@ resulting in undefined behavior such as a program crash..

class counter { -private: - boost::recursive_mutex mutex; - int count; - public: counter() : count(0) { } @@ -280,6 +279,10 @@ public: boost::recursive_mutex::scoped_lock scoped_lock(mutex); return add(1); } + +private: + boost::recursive_mutex mutex; + int count; }; counter c; diff --git a/doc/scoped_lock.html b/doc/scoped_lock.html index 022e4656..a90ba6d2 100644 --- a/doc/scoped_lock.html +++ b/doc/scoped_lock.html @@ -56,10 +56,13 @@ mutexes.

The type used to instantiate the class must meet the Mutex requirements.

+

Although this class is an implementation detail, it is publicly documented here because +of its importance.

+

Header

-#include <boost/thread/xlock.hpp>
+#include <boost/thread/detail/lock.hpp>
     This header is usually not included directly by programmers
     because it is supplied by <boost/thread/mutex.hpp> or
     <boost/thread/recursive_mutex.hpp>
@@ -70,12 +73,13 @@ mutexes.

 namespace boost { namespace detail { namespace thread {
     template <typename Mutex>
-    class scoped_lock : private boost::noncopyable
+    class scoped_lock : private boost::noncopyable // Exposition only.
+        // Class scoped_lock meets the NonCopyable requirement.
     {
     public:
         typedef Mutex mutex_type;
         
-        explicit scoped_lock(Mutex& mx, bool lock_it=true);
+        explicit scoped_lock(Mutex& mx, bool initially_locked=true);
         ~scoped_lock();
         
         void lock();
@@ -96,11 +100,11 @@ namespace boost { namespace detail { namespace thread {
 

Constructor

-    explicit scoped_lock(Mutex& mx, bool lock_it=true);
+    explicit scoped_lock(Mutex& mx, bool initially_locked=true);
 

Effects: Associates mutex mx with *this. -If lock_it is true, calls lock().

+If initially_locked is true, calls lock().


@@ -140,7 +144,7 @@ shown in the following table:

Throws lock_error. - Unspecified + Unchecked Undefined behavior [ISO 1.3.12] (but typically, deadlock.) diff --git a/doc/scoped_timed_lock.html b/doc/scoped_timed_lock.html index dc29e28a..7bf57483 100644 --- a/doc/scoped_timed_lock.html +++ b/doc/scoped_timed_lock.html @@ -54,10 +54,13 @@ mutexes.

The type used to instantiate the class must meet the TimedMutex requirements.

+

Although this class is an implementation detail, it is publicly documented here because +of its importance.

+

Header

-#include <boost/thread/xlock.hpp>
+#include <boost/thread/detail/lock.hpp>
     This header is usually not included directly by programmers
     because it is supplied by <boost/thread/mutex.hpp> or
     <boost/thread/recursive_mutex.hpp>
@@ -68,13 +71,14 @@ mutexes.

 namespace boost { namespace detail { namespace thread {
     template <typename TimedMutex>
-    class scoped_timed_lock : private boost::noncopyable
+    class scoped_timed_lock : private boost::noncopyable // Exposition only.
+        // Class scoped_timed_lock meets the NonCopyable requirement.
     {
     public:
         typedef TimedMutex mutex_type;
 
         scoped_timed_lock(TimedMutex& mx, const boost::xtime& xt);
-        scoped_timed_lock(TimedMutex& mx, bool lock_it);
+        scoped_timed_lock(TimedMutex& mx, bool initially_locked);
         ~scoped_timed_lock();
         
         void lock();
@@ -104,11 +108,11 @@ Calls timed_lock( xt)


-    scoped_timed_lock(TimedMutex& mx, bool lock_it);
+    scoped_timed_lock(TimedMutex& mx, bool initially_locked);
 

Effects: Associates mutex mx with *this. -If lock_it is true, calls lock().

+If initially_locked is true, calls lock().


@@ -148,7 +152,7 @@ shown in the following table:

Throws lock_error. - Unspecified + Unchecked Undefined behavior [ISO 1.3.12] (but typically, deadlock.) diff --git a/doc/scoped_try_lock.html b/doc/scoped_try_lock.html index ce191e90..286e9209 100644 --- a/doc/scoped_try_lock.html +++ b/doc/scoped_try_lock.html @@ -52,12 +52,15 @@ the end of the enclosing scope. The lock() and unlock() members are usually not explicitly called, but are provided to allow for complex overlapping locks of multiple mutexes.

+

Although this class is an implementation detail, it is publicly documented here because +of its importance.

+

The type used to instantiate the class must meet the TryMutex requirements.

Header

-#include <boost/thread/xlock.hpp>
+#include <boost/thread/detail/lock.hpp>
     This header is usually not included directly by programmers
     because it is supplied by <boost/thread/mutex.hpp> or
     <boost/thread/recursive_mutex.hpp>
@@ -68,13 +71,14 @@ mutexes.

 namespace boost { namespace detail { namespace thread {
     template <typename TryMutex>
-    class scoped_try_lock : private boost::noncopyable
+    class scoped_try_lock : private boost::noncopyable // Exposition only.
+        // Class scoped_try_lock meets the NonCopyable requirement.
     {
     public:
         typedef TryMutex mutex_type;
         
         explicit scoped_try_lock(TryMutex& mx);
-        scoped_try_lock(TryMutex& mx, bool lock_it);
+        scoped_try_lock(TryMutex& mx, bool initially_locked);
         ~scoped_try_lock();
         
         void lock();
@@ -103,11 +107,11 @@ Calls try_lock().


-    scoped_try_lock(TryMutex& mx, bool lock_it);
+    scoped_try_lock(TryMutex& mx, bool initially_locked);
 

Effects: Associates mutex mx with *this. -If lock_it is true, calls lock().

+If initially_locked is true, calls lock().


Destructor

@@ -147,7 +151,7 @@ shown in the following table:

Throws lock_error. - Unspecified + Unchecked Undefined behavior [ISO 1.3.12] (but typically, deadlock.) diff --git a/doc/semaphore.html b/doc/semaphore.html index 9fd336eb..5b7e4cb0 100644 --- a/doc/semaphore.html +++ b/doc/semaphore.html @@ -79,7 +79,8 @@ was V (short for the Dutch "vrygeven", "to release").
 namespace boost
 {
-    class semaphore : private boost::noncopyable
+    class semaphore : private boost::noncopyable // Exposition only.
+        // Class semaphore meets the NonCopyable requirement.
     {
     public:
         explicit semaphore(unsigned count=0, unsigned max=0);
@@ -181,7 +182,7 @@ or xt is reached. Finally, --m_count. 
 
 namespace boost {
 
-class thread : boost::noncopyable
+class thread : boost::noncopyable // Exposition only.
+   // Class thread meets the NonCopyable requirement.
 {
 public:
     thread();
@@ -166,7 +167,7 @@ represent the same thread of execution.

void join();
-

Requires: *this != thread() and *this is joinable.

+

Requires: *this is joinable.

Effects: The current thread of execution blocks until the initial function of the thread of execution represented by *this finishes and all resources @@ -174,6 +175,10 @@ are reclaimed.

Postcondition: *this is non-joinable.

+

Note:

If *this == thread() the result is implementation defined. +If the implementation doesn't detect this the result will be +deadlock.

+

sleep

@@ -202,7 +207,7 @@ implementations.

 #include <boost/thread/thread.hpp>
-#include <iostram>
+#include <iostream>
 
 struct thread_alarm
 {
diff --git a/doc/thread_specific_ptr.html b/doc/thread_specific_ptr.html
index 1dc3215c..f047e0d1 100644
--- a/doc/thread_specific_ptr.html
+++ b/doc/thread_specific_ptr.html
@@ -63,7 +63,8 @@ when the thread terminates. Each thread initially stores the null pointer in eac
 namespace boost {
 
 template <typename T>
-class thread_specific_ptr : private boost::noncopyable
+class thread_specific_ptr : private boost::noncopyable // Exposition only.
+    // Class thread_specific_ptr meets the NonCopyable requirement.
 {
 public:
     thread_specific_ptr();
@@ -183,7 +184,7 @@ void increment()
 
 void thread_proc()
 {
-   value.set(new int(0)); // initialize the thread's storage
+   value.reset(new int(0)); // initialize the thread's storage
    for (int i=0; i<10; ++i)
    {
        increment();
diff --git a/include/boost/thread/xlock.hpp b/include/boost/thread/detail/lock.hpp
similarity index 92%
rename from include/boost/thread/xlock.hpp
rename to include/boost/thread/detail/lock.hpp
index fb6ea86b..b4a81762 100644
--- a/include/boost/thread/xlock.hpp
+++ b/include/boost/thread/detail/lock.hpp
@@ -26,14 +26,12 @@ struct xtime;
     class scoped_lock : private noncopyable
     {
     public:
-        friend class boost::condition;
-    
         typedef Mutex mutex_type;
     
-        explicit scoped_lock(Mutex& mx, bool lock_it=true)
+        explicit scoped_lock(Mutex& mx, bool initially_locked=true)
             : m_mutex(mx), m_locked(false)
         {
-            if (lock_it) lock();
+            if (initially_locked) lock();
         }
         ~scoped_lock()
         {
@@ -57,6 +55,8 @@ struct xtime;
         operator const void*() const { return m_locked ? this : 0; }
     
     private:
+        friend class boost::condition;
+    
         Mutex& m_mutex;
         bool m_locked;
     };
@@ -65,8 +65,6 @@ struct xtime;
     class scoped_try_lock : private noncopyable
     {
     public:
-        friend class boost::condition;
-    
         typedef TryMutex mutex_type;
     
         explicit scoped_try_lock(TryMutex& mx)
@@ -74,10 +72,10 @@ struct xtime;
         {
             try_lock();
         }
-        scoped_try_lock(TryMutex& mx, bool lock_it)
+        scoped_try_lock(TryMutex& mx, bool initially_locked)
             : m_mutex(mx), m_locked(false)
         {
-            if (lock_it) lock();
+            if (initially_locked) lock();
         }
         ~scoped_try_lock()
         {
@@ -106,6 +104,8 @@ struct xtime;
         operator const void*() const { return m_locked ? this : 0; }
     
     private:
+        friend class boost::condition;
+    
         TryMutex& m_mutex;
         bool m_locked;
     };
@@ -114,8 +114,6 @@ struct xtime;
     class scoped_timed_lock : private noncopyable
     {
     public:
-        friend class boost::condition;
-    
         typedef TimedMutex mutex_type;
     
         scoped_timed_lock(TimedMutex& mx, const xtime& xt)
@@ -123,10 +121,10 @@ struct xtime;
         {
             timed_lock(xt);
         }
-        scoped_timed_lock(TimedMutex& mx, bool lock_it)
+        scoped_timed_lock(TimedMutex& mx, bool initially_locked)
             : m_mutex(mx), m_locked(false)
         {
-            if (lock_it) lock();
+            if (initially_locked) lock();
         }
         ~scoped_timed_lock()
         {
@@ -155,6 +153,8 @@ struct xtime;
         operator const void*() const { return m_locked ? this : 0; }
     
     private:
+        friend class boost::condition;
+    
         TimedMutex& m_mutex;
         bool m_locked;
     };
diff --git a/include/boost/thread/mutex.hpp b/include/boost/thread/mutex.hpp
index a5bef794..9a550c5a 100644
--- a/include/boost/thread/mutex.hpp
+++ b/include/boost/thread/mutex.hpp
@@ -18,7 +18,7 @@
 #endif
 
 #include 
-#include 
+#include 
 
 #if defined(BOOST_HAS_PTHREADS)
 #   include 
diff --git a/include/boost/thread/once.hpp b/include/boost/thread/once.hpp
index 6382a9b9..1524f2cb 100644
--- a/include/boost/thread/once.hpp
+++ b/include/boost/thread/once.hpp
@@ -42,4 +42,4 @@ void call_once(void (*func)(), once_flag& flag);
 // Change Log:
 //   1 Aug 01  WEKEMPF Initial version.
 
-#endif // BOOST_ONCE_WEK080101_HPP
\ No newline at end of file
+#endif // BOOST_ONCE_WEK080101_HPP
diff --git a/include/boost/thread/recursive_mutex.hpp b/include/boost/thread/recursive_mutex.hpp
index fbabbb49..f1584bd1 100644
--- a/include/boost/thread/recursive_mutex.hpp
+++ b/include/boost/thread/recursive_mutex.hpp
@@ -18,7 +18,7 @@
 #endif
 
 #include 
-#include 
+#include 
 
 #if defined(BOOST_HAS_PTHREADS)
 #   include 
diff --git a/include/boost/thread/thread.hpp b/include/boost/thread/thread.hpp
index cd98c412..179f598c 100644
--- a/include/boost/thread/thread.hpp
+++ b/include/boost/thread/thread.hpp
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #if defined(BOOST_HAS_PTHREADS)
 #   include 
@@ -64,7 +65,7 @@ public:
     ~thread_group();
 
     thread* create_thread(const function0& threadfunc);
-    void add_thread(thread* thrd);
+    void add_thread(std::auto_ptr thrd);
     void remove_thread(thread* thrd);
     void join_all();
 
diff --git a/include/boost/thread/xtime.hpp b/include/boost/thread/xtime.hpp
index 9a76c8ba..f5b56ca1 100644
--- a/include/boost/thread/xtime.hpp
+++ b/include/boost/thread/xtime.hpp
@@ -12,7 +12,7 @@
 #ifndef BOOST_XTIME_WEK070601_HPP
 #define BOOST_XTIME_WEK070601_HPP
 
-#include 
+#include 
 #include 
 
 namespace boost {
diff --git a/src/condition.cpp b/src/condition.cpp
index 075c8ecf..7b63669e 100644
--- a/src/condition.cpp
+++ b/src/condition.cpp
@@ -301,8 +301,6 @@ bool condition::do_timed_wait(const xtime& xt)
 condition::condition()
 {
     int res = pthread_cond_init(&m_condition, 0);
-    assert(res == 0);
-
     if (res != 0)
         throw thread_resource_error();
 }
diff --git a/src/mutex.cpp b/src/mutex.cpp
index 3459f143..5ae93504 100644
--- a/src/mutex.cpp
+++ b/src/mutex.cpp
@@ -31,8 +31,6 @@ namespace boost {
 mutex::mutex()
 {
     m_mutex = reinterpret_cast(CreateMutex(0, 0, 0));
-    assert(m_mutex);
-
     if (!m_mutex)
         throw thread_resource_error();
 }
@@ -68,8 +66,6 @@ void mutex::do_unlock(cv_state& state)
 try_mutex::try_mutex()
 {
     m_mutex = reinterpret_cast(CreateMutex(0, 0, 0));
-    assert(m_mutex);
-
     if (!m_mutex)
         throw thread_resource_error();
 }
@@ -112,8 +108,6 @@ void try_mutex::do_unlock(cv_state& state)
 timed_mutex::timed_mutex()
 {
     m_mutex = reinterpret_cast(CreateMutex(0, 0, 0));
-    assert(m_mutex);
-
     if (!m_mutex)
         throw thread_resource_error();
 }
@@ -166,8 +160,6 @@ void timed_mutex::do_unlock(cv_state& state)
 mutex::mutex()
 {
     int res = pthread_mutex_init(&m_mutex, 0);
-    assert(res == 0);
-
     if (res != 0)
         throw thread_resource_error();
 }
@@ -204,8 +196,6 @@ void mutex::do_unlock(cv_state& state)
 try_mutex::try_mutex()
 {
     int res = pthread_mutex_init(&m_mutex, 0);
-    assert(res == 0);
-
     if (res != 0)
         throw thread_resource_error();
 }
@@ -251,14 +241,10 @@ timed_mutex::timed_mutex()
     : m_locked(false)
 {
     int res = pthread_mutex_init(&m_mutex, 0);
-    assert(res == 0);
-
     if (res != 0)
         throw thread_resource_error();
 
     res = pthread_cond_init(&m_condition, 0);
-    assert(res == 0);
-
     if (res != 0)
     {
         pthread_mutex_destroy(&m_mutex);
diff --git a/src/recursive_mutex.cpp b/src/recursive_mutex.cpp
index 224b1d14..3f09d276 100644
--- a/src/recursive_mutex.cpp
+++ b/src/recursive_mutex.cpp
@@ -31,8 +31,6 @@ recursive_mutex::recursive_mutex()
     : m_count(0)
 {
     m_mutex = reinterpret_cast(CreateMutex(0, 0, 0));
-    assert(m_mutex);
-
     if (!m_mutex)
         throw thread_resource_error();
 }
@@ -85,8 +83,6 @@ recursive_try_mutex::recursive_try_mutex()
     : m_count(0)
 {
     m_mutex = reinterpret_cast(CreateMutex(0, 0, 0));
-    assert(m_mutex);
-
     if (!m_mutex)
         throw thread_resource_error();
 }
@@ -156,8 +152,6 @@ recursive_timed_mutex::recursive_timed_mutex()
     : m_count(0)
 {
     m_mutex = reinterpret_cast(CreateMutex(0, 0, 0));
-    assert(m_mutex);
-
     if (!m_mutex)
         throw thread_resource_error();
 }
@@ -259,15 +253,11 @@ recursive_mutex::recursive_mutex()
 #   endif
 
     res = pthread_mutex_init(&m_mutex, &attr);
-    assert(res == 0);
-
     if (res != 0)
         throw thread_resource_error();
 
 #   if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE)
     res = pthread_cond_init(&m_unlocked, 0);
-    assert(res == 0);
-
     if (res != 0)
     {
         pthread_mutex_destroy(&m_mutex);
@@ -409,15 +399,11 @@ recursive_try_mutex::recursive_try_mutex()
 #   endif
 
     res = pthread_mutex_init(&m_mutex, &attr);
-    assert(res == 0);
-
     if (res != 0)
         throw thread_resource_error();
 
 #   if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE)
     res = pthread_cond_init(&m_unlocked, 0);
-    assert(res == 0);
-
     if (res != 0)
     {
         pthread_mutex_destroy(&m_mutex);
@@ -589,14 +575,10 @@ recursive_timed_mutex::recursive_timed_mutex()
     : m_valid_id(false), m_count(0)
 {
     int res = pthread_mutex_init(&m_mutex, 0);
-    assert(res == 0);
-
     if (res != 0)
         throw thread_resource_error();
     
     res = pthread_cond_init(&m_unlocked, 0);
-    assert(res == 0);
-
     if (res != 0)
     {
         pthread_mutex_destroy(&m_mutex);
diff --git a/src/semaphore.cpp b/src/semaphore.cpp
index 16e9a34d..8169c094 100644
--- a/src/semaphore.cpp
+++ b/src/semaphore.cpp
@@ -35,8 +35,6 @@ semaphore::semaphore(unsigned count, unsigned max)
         max = std::numeric_limits::max();
 
     m_sema = reinterpret_cast(CreateSemaphore(0, count, max, 0));
-    assert(m_sema != 0);
-
     if (!m_sema)
         throw thread_resource_error();
 }
@@ -78,14 +76,10 @@ semaphore::semaphore(unsigned count, unsigned max)
     : m_available(count), m_max(max ? max : std::numeric_limits::max())
 {
     int res = pthread_mutex_init(&m_mutex, 0);
-    assert(res == 0);
-
     if (res != 0)
         throw thread_resource_error();
 
     res = pthread_cond_init(&m_condition, 0);
-    assert(res == 0);
-
     if (res != 0)
     {
         pthread_mutex_destroy(&m_mutex);
diff --git a/src/thread.cpp b/src/thread.cpp
index ab8f3857..0fdcc51d 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -50,7 +50,7 @@ public:
 #if defined(BOOST_HAS_WINTHREADS)
 unsigned __stdcall thread_proxy(void* param)
 #elif defined(BOOST_HAS_PTHREADS)
-void* thread_proxy(void* param)
+static extern "C" void* thread_proxy(void* param)
 #endif
 {
     try
@@ -87,14 +87,10 @@ thread::thread(const function0& threadfunc)
     thread_param param(threadfunc);
 #if defined(BOOST_HAS_WINTHREADS)
     m_thread = _beginthreadex(0, 0, &thread_proxy, ¶m, 0, &m_id);
-    assert(m_thread);
-
     if (!m_thread)
         throw thread_resource_error();
 #elif defined(BOOST_HAS_PTHREADS)
     int res = pthread_create(&m_thread, 0, &thread_proxy, ¶m);
-    assert(res == 0);
-
     if (res != 0)
         throw thread_resource_error();
 #endif
@@ -212,16 +208,16 @@ thread* thread_group::create_thread(const function0& threadfunc)
     return thrd.release();
 }
 
-void thread_group::add_thread(thread* thrd)
+void thread_group::add_thread(std::auto_ptr thrd)
 {
     mutex::scoped_lock scoped_lock(m_mutex);
 
     // For now we'll simply ignore requests to add a thread object multiple times.
     // Should we consider this an error and either throw or return an error value?
-    std::list::iterator it = std::find(m_threads.begin(), m_threads.end(), thrd);
+    std::list::iterator it = std::find(m_threads.begin(), m_threads.end(), thrd.get());
     assert(it == m_threads.end());
     if (it == m_threads.end())
-        m_threads.push_back(thrd);
+        m_threads.push_back(thrd.release());
 }
 
 void thread_group::remove_thread(thread* thrd)
diff --git a/src/threadmon.cpp b/src/threadmon.cpp
index 1406b1be..dba2897d 100644
--- a/src/threadmon.cpp
+++ b/src/threadmon.cpp
@@ -23,6 +23,10 @@ namespace
     registered_handlers registry;
 }
 
+#if defined(__BORLANDC__)
+#define DllMain DllEntryPoint
+#endif
+
 BOOL APIENTRY DllMain(HANDLE module, DWORD reason, LPVOID)
 {
     switch (reason)
diff --git a/src/timeconv.inl b/src/timeconv.inl
index b0b14df9..311267ed 100644
--- a/src/timeconv.inl
+++ b/src/timeconv.inl
@@ -10,12 +10,12 @@
 // It is provided "as is" without express or implied warranty.
  
 namespace {
-	const unsigned MILLISECONDS_PER_SECOND = 1000;
-	const unsigned NANOSECONDS_PER_SECOND = 1000000000;
-	const unsigned NANOSECONDS_PER_MILLISECOND = 1000000;
+    const unsigned MILLISECONDS_PER_SECOND = 1000;
+    const unsigned NANOSECONDS_PER_SECOND = 1000000000;
+    const unsigned NANOSECONDS_PER_MILLISECOND = 1000000;
 
-	inline void to_time(unsigned milliseconds, boost::xtime& xt)
-	{
+    inline void to_time(unsigned milliseconds, boost::xtime& xt)
+    {
         int res = boost::xtime_get(&xt, boost::TIME_UTC);
         assert(res == boost::TIME_UTC);
 
@@ -27,7 +27,7 @@ namespace {
             ++xt.sec;
             xt.nsec -= NANOSECONDS_PER_SECOND;
         }
-	}
+    }
 
 #if defined(BOOST_HAS_PTHREADS)
     inline void to_timespec(const boost::xtime& xt, timespec& ts)
@@ -43,46 +43,46 @@ namespace {
         to_timespec(xt, ts);
     }
 
-	inline void to_timespec_duration(const boost::xtime& xt, timespec& ts)
-	{
+    inline void to_timespec_duration(const boost::xtime& xt, timespec& ts)
+    {
         boost::xtime cur;
         int res = boost::xtime_get(&cur, boost::TIME_UTC);
         assert(res == boost::TIME_UTC);
 
         if (xt.sec < cur.sec || (xt.sec == cur.sec && xt.nsec < cur.nsec))
-		{
+        {
             ts.tv_sec = 0;
             ts.tv_nsec = 0;
-		}
-		else
-		{
-			ts.tv_sec = xt.sec - cur.sec;
-			ts.tv_nsec = xt.nsec - cur.nsec;
+        }
+        else
+        {
+            ts.tv_sec = xt.sec - cur.sec;
+            ts.tv_nsec = xt.nsec - cur.nsec;
 
-			if( ts.tv_nsec < 0 )
-			{
-				ts.tv_sec -= 1;
-				ts.tv_nsec += NANOSECONDS_PER_SECOND;
-			}
-		}
-	}
+            if( ts.tv_nsec < 0 )
+            {
+                ts.tv_sec -= 1;
+                ts.tv_nsec += NANOSECONDS_PER_SECOND;
+            }
+        }
+    }
 #endif
 
-	inline void to_duration(const boost::xtime& xt, unsigned& milliseconds)
-	{
+    inline void to_duration(const boost::xtime& xt, unsigned& milliseconds)
+    {
         boost::xtime cur;
         int res = boost::xtime_get(&cur, boost::TIME_UTC);
         assert(res == boost::TIME_UTC);
 
         if (xt.sec < cur.sec || (xt.sec == cur.sec && xt.nsec < cur.nsec))
             milliseconds = 0;
-		else
-		{
-			milliseconds = ((xt.sec - cur.sec) * MILLISECONDS_PER_SECOND) +
-				(((xt.nsec - cur.nsec) + (NANOSECONDS_PER_MILLISECOND/2))
-				/ NANOSECONDS_PER_MILLISECOND);
-		}
-	}
+        else
+        {
+            milliseconds = static_cast(((xt.sec - cur.sec) * MILLISECONDS_PER_SECOND) +
+                (((xt.nsec - cur.nsec) + (NANOSECONDS_PER_MILLISECOND/2)) /
+                NANOSECONDS_PER_MILLISECOND));
+        }
+    }
 }
 
 // Change Log:
diff --git a/src/tss.cpp b/src/tss.cpp
index 1600635f..6c93253f 100644
--- a/src/tss.cpp
+++ b/src/tss.cpp
@@ -79,8 +79,6 @@ namespace boost { namespace detail {
 tss::tss(void (*cleanup)(void*))
 {
     m_key = TlsAlloc();
-    assert(m_key != 0xFFFFFFFF);
-
     if (m_key == 0xFFFFFFFF)
         throw thread_resource_error();
 
@@ -115,8 +113,6 @@ bool tss::set(void* value)
 tss::tss(void (*cleanup)(void*))
 {
     int res = pthread_key_create(&m_key, cleanup);
-    assert(res == 0);
-
     if (res != 0)
         throw thread_resource_error();
 }
diff --git a/src/xtime.cpp b/src/xtime.cpp
index 05bd8c86..a6ebe862 100644
--- a/src/xtime.cpp
+++ b/src/xtime.cpp
@@ -45,7 +45,7 @@ int xtime_get(struct xtime* xtp, int clock_type)
         xtp->nsec = ts.tv_nsec;
         return clock_type;
 #else
-        return 0;
+#   error "xtime_get implementation undefined"
 #endif
     }
     return 0;