Modified PosixThreadFactory
Added explicit detached getter and setter
Modified PosixThreadFactory::~PThread:
Check for join failing and don't transition to detached_ state if it does. Potential thread-handle leak for
threads created joinable who aren't referenced by any external thread. Solution for now has to be
"DONT DO THAT", the clever approach doesn't always work.
Added ThreadFactoryTests.floodNThreads:
Loop M times for N threads where M x N is bigger than 32K to verify that detached threads can be created
ad infinitum.
Reviewed By: mcslee
Revert Plan: revertible
Test Plan: concurrency_test thread-factory passes
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665130 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/PosixThreadFactory.h b/lib/cpp/src/concurrency/PosixThreadFactory.h
index 16be14d..894d5f5 100644
--- a/lib/cpp/src/concurrency/PosixThreadFactory.h
+++ b/lib/cpp/src/concurrency/PosixThreadFactory.h
@@ -11,10 +11,10 @@
#include <boost/shared_ptr.hpp>
-namespace facebook { namespace thrift { namespace concurrency {
+namespace facebook { namespace thrift { namespace concurrency {
/**
- * A thread factory to create posix threads
+ * A thread factory to create posix threads
*
* @author marc
* @version $Id:$
@@ -52,20 +52,20 @@
DECREMENT = 8
};
- /**
- * Posix thread (pthread) factory. All threads created by a factory are reference-counted
- * via boost::shared_ptr and boost::weak_ptr. The factory guarantees that threads and
+ /**
+ * Posix thread (pthread) factory. All threads created by a factory are reference-counted
+ * via boost::shared_ptr and boost::weak_ptr. The factory guarantees that threads and
* the Runnable tasks they host will be properly cleaned up once the last strong reference
* to both is given up.
*
* Threads are created with the specified policy, priority, stack-size and detachable-mode
- * detached means the thread is free-running and will release all system resources the
- * when it completes. A detachable thread is not joinable. The join method
- * of a detachable thread will return immediately with no error.
+ * detached means the thread is free-running and will release all system resources the
+ * when it completes. A detachable thread is not joinable. The join method
+ * of a detachable thread will return immediately with no error.
*
* Joinable threads will detach themselves iff they were not explicitly joined and
* there are no remaining strong references to the thread. This guarantees that
- * joinnable threads don't leak resources even when the application neglects to
+ * joinnable threads don't leak resources even when the application neglects to
* call join explicitly.
*
* By default threads are joinable.
@@ -77,32 +77,42 @@
boost::shared_ptr<Thread> newThread(boost::shared_ptr<Runnable> runnable) const;
// From ThreadFactory;
- Thread::id_t currentThreadId() const;
-
- /**
- * Sets stack size for created threads
- *
- * @param value size in megabytes
- */
- virtual void stackSize(int value);
+ Thread::id_t getCurrentThreadId() const;
/**
* Gets stack size for created threads
*
* @return int size in megabytes
*/
- virtual int stackSize() const;
+ virtual int getStackSize() const;
/**
- * Sets priority relative to current policy
+ * Sets stack size for created threads
+ *
+ * @param value size in megabytes
*/
- virtual void priority(PRIORITY priority);
+ virtual void setStackSize(int value);
/**
* Gets priority relative to current policy
*/
- virtual PRIORITY priority() const;
-
+ virtual PRIORITY getPriority() const;
+
+ /**
+ * Sets priority relative to current policy
+ */
+ virtual void setPriority(PRIORITY priority);
+
+ /**
+ * Sets detached mode of threads
+ */
+ virtual void setDetached(bool detached);
+
+ /**
+ * Gets current detached mode
+ */
+ virtual bool isDetached() const;
+
private:
class Impl;
boost::shared_ptr<Impl> impl_;