Skip to content

Commit

Permalink
add thread name, fix warning in the example
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
MedicineYeh committed Nov 24, 2015
1 parent ab2c0bb commit 90c4561
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions example.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* */

#include <stdio.h>
#include <pthread.h>
#include "thpool.h"


Expand Down
5 changes: 5 additions & 0 deletions thpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <pthread.h>
#include <errno.h>
#include <time.h>
#include <sys/prctl.h>

#include "thpool.h"

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 90c4561

Please sign in to comment.