浏览代码

Fix: race auth_server thread create & detach

shuyin.wsy 7 年之前
父节点
当前提交
0964392b9f
共有 2 个文件被更改,包括 5 次插入2 次删除
  1. 1 0
      ChangeLog
  2. 4 2
      src/apps/relay/netengine.c

+ 1 - 0
ChangeLog

@@ -22,6 +22,7 @@ Version 4.5.0.8 'dan Eider':
 	- Add more explanation on use-auth-secret / REST in example config (by Krithin Sitaram)
 	- Add a Warning if lines in config file ends with semicolon (by heyheyjc)
 	- Fix --prod pointer bug
+	- Fix auth server thread detach race (by weishuyin)
 
 12/10/2017 Oleg Moskalenko <[email protected]>
 Version 4.5.0.7 'dan Eider':

+ 4 - 2
src/apps/relay/netengine.c

@@ -1786,11 +1786,13 @@ static void* run_auth_server_thread(void *arg)
 
 static void setup_auth_server(struct auth_server *as)
 {
-	if(pthread_create(&(as->thr), NULL, run_auth_server_thread, as)) {
+	pthread_attr_t attr;
+	if(pthread_attr_init(&attr) ||
+	   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) ||
+	   pthread_create(&(as->thr), &attr, run_auth_server_thread, as)) {
 		perror("Cannot create auth thread\n");
 		exit(-1);
 	}
-	pthread_detach(as->thr);
 }
 
 static void* run_admin_server_thread(void *arg)