aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-08-06 23:43:03 +0800
committerchai <chaifix@163.com>2018-08-06 23:43:03 +0800
commit27c16761d1a340e36a30edf1a6e0602644982d7f (patch)
treecc7505756e4f5c5b7e9fc125ef83c19c13771327
parentc8f9cd5530bff6cdb657885a3f9bd69cfbd50231 (diff)
*update
-rw-r--r--libjin/Thread/Thread.cpp1
-rw-r--r--libjin/Thread/Thread.h75
2 files changed, 52 insertions, 24 deletions
diff --git a/libjin/Thread/Thread.cpp b/libjin/Thread/Thread.cpp
index 81db72c..9caae87 100644
--- a/libjin/Thread/Thread.cpp
+++ b/libjin/Thread/Thread.cpp
@@ -145,7 +145,6 @@ namespace thread
void Thread::ThreadData::set(std::string name, Value value)
{
Lock l(mutex);
- //if (share.count(name) != 0);
share[name] = value;
}
diff --git a/libjin/Thread/Thread.h b/libjin/Thread/Thread.h
index b2087eb..1be1e9b 100644
--- a/libjin/Thread/Thread.h
+++ b/libjin/Thread/Thread.h
@@ -17,28 +17,28 @@ namespace jin
{
namespace thread
{
- /*
- * ӢӢMutual exclusionд Mutexһڶ̱߳Уֹ߳ͬʱͬһԴ
- * ȫֱждĻơĿͨƬһһٽcritical sectionɡٽ
- * ָһԹԴзʵĴ룬һֻƻ㷨һ򡢽̡߳̿ӵжٽ򣬵Dz
- * һӦûҪ˻ƵԴУꡢСжϴڶеĴ
- * ݡͬ״̬ȵԴάЩԴͬһºǺѵģΪһ߳̿κһʱ̱ͣ
- * ߣ߻ָѣ
- */
+ /**
+ * ӢӢMutual exclusionд Mutexһڶ̱߳Уֹ߳ͬʱͬһԴ
+ * ȫֱждĻơĿͨƬһһٽcritical sectionɡٽ
+ * ָһԹԴзʵĴ룬һֻƻ㷨һ򡢽̡߳̿ӵжٽ򣬵Dz
+ * һӦûҪ˻ƵԴУꡢСжϴڶеĴ
+ * ݡͬ״̬ȵԴάЩԴͬһºǺѵģΪһ߳̿κһʱ̱ͣ
+ * ߣ߻ָѣ
+ */
class Mutex;
class Conditional;
- /*
- * Thread:demand Receive a message from a thread. Wait for the message to exist before returning.
- * Thread:getName Get the name of a thread.
- * Thread:kill Forcefully terminate the thread.
- * Thread:peek Receive a message from a thread, but leave it in the message box.
- * Thread:receive Receive a message from a thread.
- * Thread:send Send a message.
- * Thread:set Set a value.
- * Thread:start Starts the thread.
- * Thread:wait Wait for a thread to finish.
- */
+ /**
+ * Thread::demand Receive a message from a thread. Wait for the message to exist before returning.
+ * Thread::getName Get the name of a thread.
+ * Thread::kill Forcefully terminate the thread.
+ * Thread::peek Receive a message from a thread, but leave it in the message box.
+ * Thread::receive Receive a message from a thread.
+ * Thread::send Send a message.
+ * Thread::set Set a value.
+ * Thread::start Starts the thread.
+ * Thread::wait Wait for a thread to finish.
+ */
class Thread
{
public:
@@ -47,12 +47,14 @@ namespace thread
int integer;
bool boolean;
char character;
+ const char* cstring;
void* pointer;
Value() {};
Value(int i) : integer(i) {};
Value(bool b) : boolean(b) {};
Value(char c) : character(c) {};
+ Value(const char* s) : cstring(s) {};
Value(void* p) : pointer(p) {};
};
@@ -74,7 +76,7 @@ namespace thread
};
public:
- typedef int(ThreadRunner)(Thread* thread);
+ typedef void(ThreadRunner)(Thread* thread);
Thread(const std::string name, ThreadRunner threadfuncs);
~Thread();
bool start();
@@ -87,8 +89,6 @@ namespace thread
bool isRunning();
void lock();
void unlock();
- //void kill();
- //Value peek();
private:
#if JIN_THREAD_SDL
@@ -100,7 +100,36 @@ namespace thread
Conditional* condition; // condition variable
ThreadRunner* threadRunner; // thread function
ThreadData* common; // threads common data
- std::string name; // thread name
+ const std::string name; // thread name, for debugging purposes
+ /**
+ * https://stackoverflow.com/questions/149932/naming-conventions-for-threads
+ *
+ * Use short names because they don't make the lines in a log file too long.
+ *
+ * Create names where the important part is at the beginning. Log viewers in a
+ * graphical user interface tend to have tables with columns, and the thread
+ * column is usually small or will be made small by you to read everything else.
+ *
+ * Do not use the word "thread" in the thread name because it is obvious.
+ *
+ * Make the thread names easily grep-able. Avoid similar sounding thread names
+ *
+ * If you have several threads of the same nature, enumerate them with IDs that
+ * are unique to one execution of the application or one log file, whichever fits
+ * your logging habits.
+ *
+ * Avoid generalizations like "WorkerThread" (how do you name the next 5 worker
+ * threads?), "GUIThread" (which GUI? is it for one window? for everything?) or
+ * "Calculation" (what does it calculate?).
+ *
+ * If you have a test group that uses thread names to grep your application's log
+ * files, do not rename your threads after some time. Your testers will hate you for
+ * doing so. Thread names in well-tested applications should be there to stay.
+ *
+ * When you have threads that service a network connection, try to include the target
+ * network address in the thread name (e.g. channel_123.212.123.3). Don't forget about
+ * enumeration though if there are multiple connections to the same host.
+ */
bool running; // running
static int ThreadFunciton(void* p);