MINOR: threads: Add nbthread parameter

It is only parsed and initialized for now. It will be used later. This parameter
is only available when support for threads was built in.
diff --git a/doc/configuration.txt b/doc/configuration.txt
index 59bbc56..6f7a99f 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -542,6 +542,7 @@
    - log-send-hostname
    - lua-load
    - nbproc
+   - nbthread
    - node
    - pidfile
    - presetenv
@@ -826,6 +827,13 @@
   process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES
   IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon".
 
+nbthread <number>
+  This setting is only available when support for threads was built in. It
+  creates <number> threads for each created processes. It means if HAProxy is
+  started in foreground, it only creates <number> threads for the first
+  process. FOR NOW, THREADS SUPPORT IN HAPROXY IS HIGHLY EXPERIMENTAL AND IT
+  MUST BE ENABLED WITH CAUTION AND AT YOUR OWN RISK. See also "nbproc".
+
 pidfile <pidfile>
   Writes pids of all daemons into file <pidfile>. This option is equivalent to
   the "-p" command line argument. The file must be accessible to the user
diff --git a/include/types/global.h b/include/types/global.h
index 205a494..1b2148b 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -86,6 +86,7 @@
 	int gid;
 	int external_check;
 	int nbproc;
+	int nbthread;
 	unsigned int hard_stop_after;	/* maximum time allowed to perform a soft-stop */
 	int maxconn, hardmaxconn;
 	int maxsslconn;
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 4db59a3..1cb98f3 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -1041,6 +1041,30 @@
 			goto out;
 		}
 	}
+	else if (!strcmp(args[0], "nbthread")) {
+		if (alertif_too_many_args(1, file, linenum, args, &err_code))
+			goto out;
+		if (*(args[1]) == 0) {
+			Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
+			err_code |= ERR_ALERT | ERR_FATAL;
+			goto out;
+		}
+		global.nbthread = atol(args[1]);
+		if (global.nbthread < 1 || global.nbthread > LONGBITS) {
+			Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
+			      file, linenum, args[0], LONGBITS, global.nbthread);
+			err_code |= ERR_ALERT | ERR_FATAL;
+			goto out;
+		}
+#ifndef USE_THREAD
+		if (global.nbthread > 1) {
+			Alert("HAProxy is not compiled with threads support, please check build options for USE_THREAD.\n");
+			global.nbthread = 1;
+			err_code |= ERR_ALERT | ERR_FATAL;
+			goto out;
+		}
+#endif
+	}
 	else if (!strcmp(args[0], "maxconn")) {
 		if (alertif_too_many_args(1, file, linenum, args, &err_code))
 			goto out;
diff --git a/src/haproxy.c b/src/haproxy.c
index a4e62a7..bd8dfd6 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -77,6 +77,7 @@
 #include <common/time.h>
 #include <common/uri_auth.h>
 #include <common/version.h>
+#include <common/hathreads.h>
 
 #include <types/capture.h>
 #include <types/filters.h>
@@ -122,6 +123,7 @@
 struct global global = {
 	.hard_stop_after = TICK_ETERNITY,
 	.nbproc = 1,
+	.nbthread = 1,
 	.req_count = 0,
 	.logsrvs = LIST_HEAD_INIT(global.logsrvs),
 	.maxzlibmem = 0,
@@ -1754,6 +1756,9 @@
 	if (global.nbproc < 1)
 		global.nbproc = 1;
 
+	if (global.nbthread < 1)
+		global.nbthread = 1;
+
 	/* Realloc trash buffers because global.tune.bufsize may have changed */
 	if (!init_trash_buffers()) {
 		Alert("failed to initialize trash buffers.\n");