add thread name, fix warning in the example

thread name is good for both profiling and debuging
also htop can turn on the option 'Show custom thread names' in 'Display
options'
the warning in example is ‘pthread_self’ [-Wimplicit-function-declaration]
This commit is contained in:
MedicineYeh 2015-11-24 12:47:50 +08:00
parent ab2c0bb8ad
commit 90c4561942
2 changed files with 6 additions and 0 deletions

View File

@ -12,6 +12,7 @@
* */
#include <stdio.h>
#include <pthread.h>
#include "thpool.h"

View File

@ -16,6 +16,7 @@
#include <pthread.h>
#include <errno.h>
#include <time.h>
#include <sys/prctl.h>
#include "thpool.h"
@ -335,6 +336,10 @@ static void thread_hold () {
* @return nothing
*/
static void* thread_do(struct thread* thread_p){
/* Set thread name for profiling and debuging */
char thread_name[128] = {0};
sprintf(thread_name, "thread-pool-%d", thread_p->id);
prctl(PR_SET_NAME, thread_name);
/* Assure all threads have been created before starting serving */
thpool_* thpool_p = thread_p->thpool_p;